moonbridge

diff moonbridge_io.c @ 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 930a43a0099a
children 1b459e9c12c9
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

Impressum / About Us