diff options
author | Steven Barth <steven@midlink.org> | 2009-02-27 14:51:37 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-02-27 14:51:37 +0000 |
commit | 7196b2cd848577f640d9268a0a34ab3ad8706c26 (patch) | |
tree | 94b74ea2ba96fdc6135c6af807e925f064a2db28 /libs/nixio/src/poll.c | |
parent | 30421d38dd004a8c1e149e40af2019cbbc4c8bd6 (diff) |
nixio: Fixes, use POSIX calls for file i/o
httpclient: resume support, splice() support, cookie support
Diffstat (limited to 'libs/nixio/src/poll.c')
-rw-r--r-- | libs/nixio/src/poll.c | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/libs/nixio/src/poll.c b/libs/nixio/src/poll.c index 8fd585f22..fdec2caaf 100644 --- a/libs/nixio/src/poll.c +++ b/libs/nixio/src/poll.c @@ -20,6 +20,7 @@ #include <poll.h> #include <time.h> #include <errno.h> +#include <string.h> #include <stdlib.h> #include "nixio.h" @@ -49,18 +50,6 @@ static int nixio_nanosleep(lua_State *L) { } /** - * Checks whether a flag is set in the table and translates it into a bitmap - */ -static void nixio_poll_flags__w(lua_State *L, int *map, int f, const char *t) { - lua_pushstring(L, t); - lua_rawget(L, -2); - if (lua_toboolean(L, -1)) { - *map |= f; - } - lua_pop(L, 1); -} - -/** * Checks whether a flag is set in the bitmap and sets the matching table value */ static void nixio_poll_flags__r(lua_State *L, int *map, int f, const char *t) { @@ -78,17 +67,7 @@ static void nixio_poll_flags__r(lua_State *L, int *map, int f, const char *t) { */ static int nixio_poll_flags(lua_State *L) { int flags; - if (lua_istable(L, 1)) { - lua_settop(L, 1); - flags = 0; - nixio_poll_flags__w(L, &flags, POLLIN, "in"); - nixio_poll_flags__w(L, &flags, POLLPRI, "pri"); - nixio_poll_flags__w(L, &flags, POLLOUT, "out"); - nixio_poll_flags__w(L, &flags, POLLERR, "err"); - nixio_poll_flags__w(L, &flags, POLLHUP, "hup"); - nixio_poll_flags__w(L, &flags, POLLNVAL, "nval"); - lua_pushinteger(L, flags); - } else { + if (lua_isnumber(L, 1)) { flags = luaL_checkinteger(L, 1); lua_newtable(L); nixio_poll_flags__r(L, &flags, POLLIN, "in"); @@ -97,6 +76,29 @@ static int nixio_poll_flags(lua_State *L) { nixio_poll_flags__r(L, &flags, POLLERR, "err"); nixio_poll_flags__r(L, &flags, POLLHUP, "hup"); nixio_poll_flags__r(L, &flags, POLLNVAL, "nval"); + } else { + flags = 0; + const int j = lua_gettop(L); + for (int i=1; i<=j; i++) { + const char *flag = luaL_checkstring(L, i); + if (!strcmp(flag, "in")) { + flags |= POLLIN; + } else if (!strcmp(flag, "pri")) { + flags |= POLLPRI; + } else if (!strcmp(flag, "out")) { + flags |= POLLOUT; + } else if (!strcmp(flag, "err")) { + flags |= POLLERR; + } else if (!strcmp(flag, "hup")) { + flags |= POLLHUP; + } else if (!strcmp(flag, "nval")) { + flags |= POLLNVAL; + } else { + return luaL_argerror(L, i, + "supported values: in, pri, out, err, hup, nval"); + } + } + lua_pushinteger(L, flags); } return 1; } |