summaryrefslogtreecommitdiffhomepage
path: root/libs/nixio
diff options
context:
space:
mode:
Diffstat (limited to 'libs/nixio')
-rw-r--r--libs/nixio/lua/nixio/util.lua33
-rw-r--r--libs/nixio/src/nixio.c12
-rw-r--r--libs/nixio/src/nixio.h4
3 files changed, 48 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
diff --git a/libs/nixio/src/nixio.c b/libs/nixio/src/nixio.c
index 5f098be31..a4ef7462e 100644
--- a/libs/nixio/src/nixio.c
+++ b/libs/nixio/src/nixio.c
@@ -123,6 +123,18 @@ LUALIB_API int luaopen_nixio(lua_State *L) {
lua_pushnumber(L, VERSION);
lua_setfield(L, -2, "version");
+ /* some constants */
+ lua_createtable(L, 0, 1);
+
+ NIXIO_PUSH_CONSTANT(EACCES);
+ NIXIO_PUSH_CONSTANT(ENOSYS);
+ NIXIO_PUSH_CONSTANT(EINVAL);
+ NIXIO_PUSH_CONSTANT(EWOULDBLOCK);
+ NIXIO_PUSH_CONSTANT(EAGAIN);
+ NIXIO_PUSH_CONSTANT(ENOMEM);
+
+ lua_setfield(L, -2, "const");
+
/* remove meta table */
lua_remove(L, -2);
diff --git a/libs/nixio/src/nixio.h b/libs/nixio/src/nixio.h
index e4bb6d6de..cdb43599e 100644
--- a/libs/nixio/src/nixio.h
+++ b/libs/nixio/src/nixio.h
@@ -6,6 +6,10 @@
#define NIXIO_BUFFERSIZE 8096
#define _FILE_OFFSET_BITS 64
+#define NIXIO_PUSH_CONSTANT(x) \
+ lua_pushinteger(L, x); \
+ lua_setfield(L, -2, #x);
+
/* uClibc: broken as always */
#define _LARGEFILE_SOURCE