moonbridge
changeset 313:334ea1f13b0b
Modified non-blocking I/O _call functions to pass certain arguments (socket, mode, module) to wait function
author | jbe |
---|---|
date | Thu Feb 01 19:13:25 2018 +0100 (2018-02-01) |
parents | c9fec96fe392 |
children | 1b459e9c12c9 |
files | moonbridge_io.c reference.txt |
line diff
1.1 --- a/moonbridge_io.c Sat Jan 27 17:54:00 2018 +0100 1.2 +++ b/moonbridge_io.c Thu Feb 01 19:13:25 2018 +0100 1.3 @@ -55,6 +55,7 @@ 1.4 moonbr_io_return_prepared_errmsg(); \ 1.5 } while (0) 1.6 1.7 +#define MOONBR_IO_MODULE_REGKEY "moonbridge_io_module" 1.8 #define MOONBR_IO_HANDLE_MT_REGKEY "moonbridge_io_handle" 1.9 #define MOONBR_IO_HANDLE_PUBLIC_MT_REGKEY "moonbridge_io_handle_public" 1.10 #define MOONBR_IO_LISTENER_MT_REGKEY "moonbridge_io_listener" 1.11 @@ -386,7 +387,10 @@ 1.12 lua_replace(L, 3); 1.13 } 1.14 lua_pushvalue(L, 2); 1.15 - lua_callk(L, 0, 0, ctx, moonbr_io_read_cont); 1.16 + lua_pushvalue(L, 1); 1.17 + lua_pushliteral(L, "r"); 1.18 + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.19 + lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); 1.20 } 1.21 if (ctx != 1) { 1.22 luaL_Buffer buf; 1.23 @@ -446,7 +450,10 @@ 1.24 lua_replace(L, 3); 1.25 } 1.26 lua_pushvalue(L, 2); 1.27 - lua_callk(L, 0, 0, ctx, moonbr_io_drain_cont); 1.28 + lua_pushvalue(L, 1); 1.29 + lua_pushliteral(L, "r"); 1.30 + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.31 + lua_callk(L, 3, 0, ctx, moonbr_io_drain_cont); 1.32 } 1.33 lua_pushinteger(L, totallen); 1.34 lua_pushvalue(L, -2); 1.35 @@ -664,6 +671,9 @@ 1.36 } 1.37 lua_pop(L, 2); 1.38 lua_pushvalue(L, 2); 1.39 + lua_pushvalue(L, 1); 1.40 + lua_pushliteral(L, "w"); 1.41 + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.42 lua_callk(L, 0, 0, 0, moonbr_io_write_cont); 1.43 } 1.44 } 1.45 @@ -2126,6 +2136,8 @@ 1.46 signal(SIGPIPE, SIG_IGN); /* generate I/O errors instead of signal 13 */ 1.47 1.48 lua_newtable(L); // module 1.49 + lua_pushvalue(L, -1); 1.50 + lua_setfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.51 1.52 lua_newtable(L); // public metatable 1.53 lua_newtable(L); // handle methods
2.1 --- a/reference.txt Sat Jan 27 17:54:00 2018 +0100 2.2 +++ b/reference.txt Thu Feb 01 19:13:25 2018 +0100 2.3 @@ -84,8 +84,8 @@ 2.4 2.5 ### socket:drain_call(waitfunc, maxlen, terminator) 2.6 2.7 -Same as socket:drain(maxlen, terminator), but calls waitfunc() (in an infinite 2.8 -loop) as long as the reading is blocked. 2.9 +Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", 2.10 +moonbridge_io) (in an infinite loop) as long as the reading is blocked. 2.11 2.12 2.13 ### socket:drain_nb(maxlen, terminator) 2.14 @@ -126,8 +126,8 @@ 2.15 2.16 ### socket:flush_call(waitfunc, ...) 2.17 2.18 -Same as socket:flush(...), but calls waitfunc() (in an infinite loop) as long 2.19 -as the writing is blocked. 2.20 +Same as socket:flush(...), but calls waitfunc(socket, "w", moonbridge_io) (in 2.21 +an infinite loop) as long as the writing is blocked. 2.22 2.23 2.24 ### socket:flush_nb(...) 2.25 @@ -192,8 +192,8 @@ 2.26 2.27 ### socket:read_call(waitfunc, maxlen, terminator) 2.28 2.29 -Same as socket:read(maxlen, terminator), but calls waitfunc() (in an infinite 2.30 -loop) as long as the reading is blocked. 2.31 +Same as socket:read(maxlen, terminator), but calls waitfunc(socket, "r", 2.32 +moonbridge_io) (in an infinite loop) as long as the reading is blocked. 2.33 2.34 2.35 ### socket:read_nb(maxlen, terminator) 2.36 @@ -262,8 +262,8 @@ 2.37 2.38 ### socket:write_call(waitfunc, ...) 2.39 2.40 -Same as socket:write(...), but calls waitfunc() (in an infinite loop) as long 2.41 -as the writing is blocked. 2.42 +Same as socket:write(...), but calls waitfunc(socket, "w", moonbridge_io) (in 2.43 +an infinite loop) as long as the writing is blocked. 2.44 2.45 2.46 ### socket:write_nb(...)