summaryrefslogtreecommitdiffhomepage
path: root/plop.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-08-15 17:38:16 +0200
committerAki <please@ignore.pl>2021-08-15 17:38:16 +0200
commit52526c295ccdbe48b4965b269482c0a9fba6e658 (patch)
treed0cb9a1432e41525f8d724ccc68d9f3dc43184bd /plop.c
parent3070ac071925261691d785b78450483f996d2e51 (diff)
downloadplop-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.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/plop.c b/plop.c
index f9d4de2..1a204da 100644
--- a/plop.c
+++ b/plop.c
@@ -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;