More nixio fixes
authorSteven Barth <steven@midlink.org>
Sun, 15 Feb 2009 13:59:30 +0000 (13:59 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 15 Feb 2009 13:59:30 +0000 (13:59 +0000)
libs/nixio/lua/nixio/util.lua
libs/nixio/src/file.c

index 8ad4040d4a676de2136452af536aad11fec63b2e..34800b4541b4c20b9563feef620cb42e0d80384d 100644 (file)
@@ -21,11 +21,13 @@ module "nixio.util"
 local BUFFERSIZE = 8096
 local socket = nixio.socket_meta
 
-function socket.readall(self, len)
+function socket.recvall(self, len)
        local block, code, msg = self:recv(len)
 
        if not block then
                return "", code, msg, len
+       elseif #block == 0 then
+               return "", nil, nil, len
        end
 
        local data, total = {block}, #block
@@ -35,6 +37,8 @@ function socket.readall(self, len)
 
                if not block then
                        return data, code, msg, len - #data
+               elseif #block == 0 then
+                       return data, nil, nil, len - #data
                end
 
                data[#data+1], total = block, total + #block
@@ -66,11 +70,12 @@ end
 function socket.linesource(self, limit)
        limit = limit or BUFFERSIZE
        local buffer = ""
+       local bpos = 0
        return function(flush)
-               local bpos, line, endp, _ = 0
+               local line, endp, _
                
                if flush then
-                       line = buffer
+                       line = buffer:sub(bpos + 1)
                        buffer = ""
                        return line
                end
index 13a40c4999ec0d0afe94d53dde6591b15cce7f85..7b65abdc12a9374cee40f88278f9de445125ab0b 100644 (file)
@@ -76,7 +76,8 @@ static int nixio_file_write(lua_State *L) {
        if (written < 0) {
                return nixio__perror(L);
        } else {
-               return written;
+               lua_pushnumber(L, written);
+               return 1;
        }
 }