diff options
author | Steven Barth <steven@midlink.org> | 2009-02-18 21:46:55 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-02-18 21:46:55 +0000 |
commit | cbc49a3b537e2e7cc49166f9d85e730d0f7d6275 (patch) | |
tree | d593ea5a84a8a1590367046074d13e65fb9ac1a2 /libs/nixio/lua | |
parent | e062ec6981cc6a351b2a79676bdfc9054db44655 (diff) |
More nixio fixes, initial httpclient
Diffstat (limited to 'libs/nixio/lua')
-rw-r--r-- | libs/nixio/lua/nixio/util.lua | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/libs/nixio/lua/nixio/util.lua b/libs/nixio/lua/nixio/util.lua index 34800b454..cb9fcf56f 100644 --- a/libs/nixio/lua/nixio/util.lua +++ b/libs/nixio/lua/nixio/util.lua @@ -77,11 +77,12 @@ function socket.linesource(self, limit) 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 @@ -89,6 +90,8 @@ function socket.linesource(self, limit) 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 @@ -97,4 +100,32 @@ function socket.linesource(self, limit) end end end +end + +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
\ No newline at end of file |