moonbridge
changeset 314:1b459e9c12c9
Added parameter to waitfunc of asynchronous I/O functions which allows to check whether waitfunc was called for the first time
author | jbe |
---|---|
date | Thu Feb 01 20:26:30 2018 +0100 (2018-02-01) |
parents | 334ea1f13b0b |
children | 15132b3c053d |
files | moonbridge_io.c reference.txt |
line diff
1.1 --- a/moonbridge_io.c Thu Feb 01 19:13:25 2018 +0100 1.2 +++ b/moonbridge_io.c Thu Feb 01 20:26:30 2018 +0100 1.3 @@ -354,7 +354,7 @@ 1.4 size_t len; 1.5 #if !(LUA_VERSION_NUM >= 503) 1.6 int ctx = 0; 1.7 - lua_getctx(L, &ctx); 1.8 + int status = lua_getctx(L, &ctx); 1.9 #endif 1.10 remaining = lua_tointeger(L, 3); 1.11 while (1) { 1.12 @@ -389,8 +389,10 @@ 1.13 lua_pushvalue(L, 2); 1.14 lua_pushvalue(L, 1); 1.15 lua_pushliteral(L, "r"); 1.16 + lua_pushboolean(L, status != LUA_YIELD); 1.17 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.18 lua_callk(L, 3, 0, ctx, moonbr_io_read_cont); 1.19 + status = LUA_YIELD; 1.20 } 1.21 if (ctx != 1) { 1.22 luaL_Buffer buf; 1.23 @@ -659,6 +661,8 @@ 1.24 static int moonbr_io_write_cont(lua_State *L, int status, lua_KContext ctx) { 1.25 #else 1.26 static int moonbr_io_write_cont(lua_State *L) { 1.27 + int ctx = 0; 1.28 + int status = lua_getctx(L, &ctx); 1.29 #endif 1.30 while (1) { 1.31 lua_pushcfunction(L, moonbr_io_write_nb); 1.32 @@ -673,8 +677,10 @@ 1.33 lua_pushvalue(L, 2); 1.34 lua_pushvalue(L, 1); 1.35 lua_pushliteral(L, "w"); 1.36 + lua_pushboolean(L, status != LUA_YIELD); 1.37 lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_MODULE_REGKEY); 1.38 lua_callk(L, 0, 0, 0, moonbr_io_write_cont); 1.39 + status = LUA_YIELD; 1.40 } 1.41 } 1.42
2.1 --- a/reference.txt Thu Feb 01 19:13:25 2018 +0100 2.2 +++ b/reference.txt Thu Feb 01 20:26:30 2018 +0100 2.3 @@ -84,8 +84,9 @@ 2.4 2.5 ### socket:drain_call(waitfunc, maxlen, terminator) 2.6 2.7 -Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", 2.8 -moonbridge_io) (in an infinite loop) as long as the reading is blocked. 2.9 +Same as socket:drain(maxlen, terminator), but calls waitfunc(socket, "r", first 2.10 +moonbridge_io) (in an infinite loop, first=true only on first call) as long as 2.11 +the reading is blocked. 2.12 2.13 2.14 ### socket:drain_nb(maxlen, terminator) 2.15 @@ -126,8 +127,9 @@ 2.16 2.17 ### socket:flush_call(waitfunc, ...) 2.18 2.19 -Same as socket:flush(...), but calls waitfunc(socket, "w", moonbridge_io) (in 2.20 -an infinite loop) as long as the writing is blocked. 2.21 +Same as socket:flush(...), but calls waitfunc(socket, "w", first, 2.22 +moonbridge_io) (in an infinite loop, first=true only on first call) as long as 2.23 +the writing is blocked. 2.24 2.25 2.26 ### socket:flush_nb(...) 2.27 @@ -192,8 +194,9 @@ 2.28 2.29 ### socket:read_call(waitfunc, maxlen, terminator) 2.30 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 +Same as socket:read(maxlen, terminator), but calls waitfunc(socket, "r", first, 2.34 +moonbridge_io) (in an infinite loop, first=true only on first call) as long as 2.35 +the reading is blocked. 2.36 2.37 2.38 ### socket:read_nb(maxlen, terminator) 2.39 @@ -262,8 +265,9 @@ 2.40 2.41 ### socket:write_call(waitfunc, ...) 2.42 2.43 -Same as socket:write(...), but calls waitfunc(socket, "w", moonbridge_io) (in 2.44 -an infinite loop) as long as the writing is blocked. 2.45 +Same as socket:write(...), but calls waitfunc(socket, "w", first, 2.46 +moonbridge_io) (in an infinite loop, first=true only on first call) as long as 2.47 +the writing is blocked. 2.48 2.49 2.50 ### socket:write_nb(...)