local BUFFERSIZE = 8096
local socket = nixio.socket_meta
+local tls_socket = nixio.tls_socket_meta
function socket.recvall(self, len)
local block, code, msg = self:recv(len)
return (#data > 1 and table.concat(data) or data[1]), nil, nil, 0
end
+tls_socket.recvall = socket.recvall
function socket.sendall(self, data)
local total, block = 0
return total + sent, nil, nil, ""
end
+tls_socket.sendall = socket.sendall
function socket.linesource(self, limit)
limit = limit or BUFFERSIZE
if flush then
line = buffer:sub(bpos + 1)
buffer = ""
+ bpos = 0
return line
end
while not line do
- _, endp, line = buffer:find("^(.-)\r?\n", bpos + 1)
+ _, endp, line = buffer:find("(.-)\r?\n", bpos + 1)
if line then
bpos = endp
return line
local newblock, code = self:recv(limit + bpos - #buffer)
if not newblock then
return nil, code
+ elseif #newblock == 0 then
+ return nil
end
buffer = buffer:sub(bpos + 1) .. newblock
bpos = 0
end
end
end
-end
\ No newline at end of file
+end
+tls_socket.linesource = socket.linesource
+
+function socket.blocksource(self, bs, limit)
+ bs = bs or BUFFERSIZE
+ return function()
+ local toread = bs
+ if limit then
+ if limit < 1 then
+ return nil
+ elseif limit < toread then
+ toread = limit
+ end
+ end
+
+ local block, code, msg = self:recv(toread)
+
+ if not block then
+ return nil, code
+ elseif #block == 0 then
+ return nil
+ else
+ if limit then
+ limit = limit - #block
+ end
+
+ return block
+ end
+ end
+end
+tls_socket.blocksource = socket.blocksource
\ No newline at end of file