diff options
author | Aki <please@ignore.pl> | 2021-08-15 17:38:16 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-08-15 17:38:16 +0200 |
commit | 52526c295ccdbe48b4965b269482c0a9fba6e658 (patch) | |
tree | d0cb9a1432e41525f8d724ccc68d9f3dc43184bd /plop.c | |
parent | 3070ac071925261691d785b78450483f996d2e51 (diff) | |
download | plop-52526c295ccdbe48b4965b269482c0a9fba6e658.zip plop-52526c295ccdbe48b4965b269482c0a9fba6e658.tar.gz plop-52526c295ccdbe48b4965b269482c0a9fba6e658.tar.bz2 |
Separated connection and server Lua state
Diffstat (limited to 'plop.c')
-rw-r--r-- | plop.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -138,6 +138,13 @@ int plop_load_handler(lua_State * L, const char * path) return LUA_OK; } +/// Drops Lua thread referenced by *ref* in the registry of main Lua state. +void plop_drop_thread(const int ref) +{ + if (LUA_NOREF != ref) + luaL_unref(plop.L, LUA_REGISTRYINDEX, ref); +} + /// Handles client events. /// \param L Server's Lua state /// \param c Connection associated with the client @@ -169,7 +176,8 @@ int plop_handle_client(lua_State * L, struct connection * c) { case LUA_OK: { - connection_free(L, c); + plop_drop_thread(c->ref); + connection_free(c); return 0; } case LUA_YIELD: @@ -187,18 +195,18 @@ int plop_handle_client(lua_State * L, struct connection * c) dprintf(2, "%s\n", err); lua_pop(c->L, 1); - connection_free(L, c); + plop_drop_thread(c->ref); + connection_free(c); return -1; } } } /// Accepts awaiting connections if any. -/// \param L Server's Lua state /// \param efd File descriptor for epoll's context /// \param server File descriptor for server socket /// \return -1 if an error occured -int plop_handle_server(lua_State * L, const int efd, const int server) +int plop_handle_server(const int efd, const int server) { struct epoll_event e; e.events = EPOLLIN | EPOLLOUT; // TODO: Add EPOLLHUP? @@ -241,7 +249,7 @@ int plop_handle_server(lua_State * L, const int efd, const int server) return 0; // TODO: Retriage this error at some point. } - struct connection * connection = connection_new(L, client); + struct connection * connection = connection_new(client); if (NULL == connection) { return -1; |