# HG changeset patch # User jbe # Date 1517508805 -3600 # Node ID 334ea1f13b0b06911365acc4194a1ab7eace077a # Parent c9fec96fe3926e418bf177f7d938d9928c158250 Modified non-blocking I/O _call functions to pass certain arguments (socket, mode, module) to wait function diff -r c9fec96fe392 -r 334ea1f13b0b moonbridge_io.c --- a/moonbridge_io.c Sat Jan 27 17:54:00 2018 +0100 +++ b/moonbridge_io.c Thu Feb 01 19:13:25 2018 +0100 @@ -55,6 +55,7 @@ moonbr_io_return_prepared_errmsg(); \ } while (0) +#define MOONBR_IO_MODULE_REGKEY "moonbridge_io_module" #define MOONBR_IO_HANDLE_MT_REGKEY "moonbridge_io_handle" #define MOONBR_IO_HANDLE_PUBLIC_MT_REGKEY "moonbridge_io_handle_public" #define MOONBR_IO_LISTENER_MT_REGKEY "moonbridge_io_listener" @@ -386,7 +387,10 @@ lua_replace(L, 3); } lua_pushvalue(L, 2); - lua_callk(L, 0, 0, ctx, moonbr_io_read_cont); + lua_pushvalue(L, 1); + lua_pushliteral(L, "r"); + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); + lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); } if (ctx != 1) { luaL_Buffer buf; @@ -446,7 +450,10 @@ lua_replace(L, 3); } lua_pushvalue(L, 2); - lua_callk(L, 0, 0, ctx, moonbr_io_drain_cont); + lua_pushvalue(L, 1); + lua_pushliteral(L, "r"); + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); + lua_callk(L, 3, 0, ctx, moonbr_io_drain_cont); } lua_pushinteger(L, totallen); lua_pushvalue(L, -2); @@ -664,6 +671,9 @@ } lua_pop(L, 2); lua_pushvalue(L, 2); + lua_pushvalue(L, 1); + lua_pushliteral(L, "w"); + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); lua_callk(L, 0, 0, 0, moonbr_io_write_cont); } } @@ -2126,6 +2136,8 @@ signal(SIGPIPE, SIG_IGN); /* generate I/O errors instead of signal 13 */ lua_newtable(L); // module + lua_pushvalue(L, -1); + lua_setfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); lua_newtable(L); // public metatable lua_newtable(L); // handle methods diff -r c9fec96fe392 -r 334ea1f13b0b reference.txt --- a/reference.txt Sat Jan 27 17:54:00 2018 +0100 +++ b/reference.txt Thu Feb 01 19:13:25 2018 +0100 @@ -84,8 +84,8 @@ ### socket:drain_call(waitfunc, maxlen, terminator) -Same as socket:drain(maxlen, terminator), but calls waitfunc() (in an infinite -loop) as long as the reading is blocked. +Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", +moonbridge_io) (in an infinite loop) as long as the reading is blocked. ### socket:drain_nb(maxlen, terminator) @@ -126,8 +126,8 @@ ### socket:flush_call(waitfunc, ...) -Same as socket:flush(...), but calls waitfunc() (in an infinite loop) as long -as the writing is blocked. +Same as socket:flush(...), but calls waitfunc(socket, "w", moonbridge_io) (in +an infinite loop) as long as the writing is blocked. ### socket:flush_nb(...) @@ -192,8 +192,8 @@ ### socket:read_call(waitfunc, maxlen, terminator) -Same as socket:read(maxlen, terminator), but calls waitfunc() (in an infinite -loop) as long as the reading is blocked. +Same as socket:read(maxlen, terminator), but calls waitfunc(socket, "r", +moonbridge_io) (in an infinite loop) as long as the reading is blocked. ### socket:read_nb(maxlen, terminator) @@ -262,8 +262,8 @@ ### socket:write_call(waitfunc, ...) -Same as socket:write(...), but calls waitfunc() (in an infinite loop) as long -as the writing is blocked. +Same as socket:write(...), but calls waitfunc(socket, "w", moonbridge_io) (in +an infinite loop) as long as the writing is blocked. ### socket:write_nb(...)