# HG changeset patch # User jbe # Date 1517513190 -3600 # Node ID 1b459e9c12c9a387e2cafbcba1f3226415a810ae # Parent 334ea1f13b0b06911365acc4194a1ab7eace077a Added parameter to waitfunc of asynchronous I/O functions which allows to check whether waitfunc was called for the first time diff -r 334ea1f13b0b -r 1b459e9c12c9 moonbridge_io.c --- a/moonbridge_io.c Thu Feb 01 19:13:25 2018 +0100 +++ b/moonbridge_io.c Thu Feb 01 20:26:30 2018 +0100 @@ -354,7 +354,7 @@ size_t len; #if !(LUA_VERSION_NUM >= 503) int ctx = 0; - lua_getctx(L, &ctx); + int status = lua_getctx(L, &ctx); #endif remaining = lua_tointeger(L, 3); while (1) { @@ -389,8 +389,10 @@ lua_pushvalue(L, 2); lua_pushvalue(L, 1); lua_pushliteral(L, "r"); + lua_pushboolean(L, status != LUA_YIELD); lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); + status = LUA_YIELD; } if (ctx != 1) { luaL_Buffer buf; @@ -659,6 +661,8 @@ static int moonbr_io_write_cont(lua_State *L, int status, lua_KContext ctx) { #else static int moonbr_io_write_cont(lua_State *L) { + int ctx = 0; + int status = lua_getctx(L, &ctx); #endif while (1) { lua_pushcfunction(L, moonbr_io_write_nb); @@ -673,8 +677,10 @@ lua_pushvalue(L, 2); lua_pushvalue(L, 1); lua_pushliteral(L, "w"); + lua_pushboolean(L, status != LUA_YIELD); lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); lua_callk(L, 0, 0, 0, moonbr_io_write_cont); + status = LUA_YIELD; } } diff -r 334ea1f13b0b -r 1b459e9c12c9 reference.txt --- a/reference.txt Thu Feb 01 19:13:25 2018 +0100 +++ b/reference.txt Thu Feb 01 20:26:30 2018 +0100 @@ -84,8 +84,9 @@ ### socket:drain_call(waitfunc, maxlen, terminator) -Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", -moonbridge_io) (in an infinite loop) as long as the reading is blocked. +Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", first +moonbridge_io) (in an infinite loop, first=true only on first call) as long as +the reading is blocked. ### socket:drain_nb(maxlen, terminator) @@ -126,8 +127,9 @@ ### socket:flush_call(waitfunc, ...) -Same as socket:flush(...), but calls waitfunc(socket, "w", moonbridge_io) (in -an infinite loop) as long as the writing is blocked. +Same as socket:flush(...), but calls waitfunc(socket, "w", first, +moonbridge_io) (in an infinite loop, first=true only on first call) as long as +the writing is blocked. ### socket:flush_nb(...) @@ -192,8 +194,9 @@ ### socket:read_call(waitfunc, maxlen, terminator) -Same as socket:read(maxlen, terminator), but calls waitfunc(socket, "r", -moonbridge_io) (in an infinite loop) as long as the reading is blocked. +Same as socket:read(maxlen, terminator), but calls waitfunc(socket, "r", first, +moonbridge_io) (in an infinite loop, first=true only on first call) as long as +the reading is blocked. ### socket:read_nb(maxlen, terminator) @@ -262,8 +265,9 @@ ### socket:write_call(waitfunc, ...) -Same as socket:write(...), but calls waitfunc(socket, "w", moonbridge_io) (in -an infinite loop) as long as the writing is blocked. +Same as socket:write(...), but calls waitfunc(socket, "w", first, +moonbridge_io) (in an infinite loop, first=true only on first call) as long as +the writing is blocked. ### socket:write_nb(...)