summaryrefslogtreecommitdiffhomepage
path: root/plop.c
diff options
context:
space:
mode:
Diffstat (limited to 'plop.c')
-rw-r--r--plop.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/plop.c b/plop.c
index 1a204da..057208a 100644
--- a/plop.c
+++ b/plop.c
@@ -146,27 +146,18 @@ void plop_drop_thread(const int ref)
}
/// Handles client events.
-/// \param L Server's Lua state
/// \param c Connection associated with the client
/// \return -1 if an error occured
-int plop_handle_client(lua_State * L, struct connection * c)
+int plop_handle_client(struct connection * c)
{
int nargs = 0;
- if (NULL == c->L)
+ if (c->push)
{
- c->L = lua_newthread(L);
-
- if (NULL == c->L)
- {
- return -1; // TODO: Fail only this connection?
- }
-
- c->ref = luaL_ref(L, LUA_REGISTRYINDEX);
-
lua_getglobal(c->L, "handler");
stream_push_new(c->L, c->fd);
nargs = 1;
+ c->push = 0;
}
int nresults = 0;
@@ -176,6 +167,7 @@ int plop_handle_client(lua_State * L, struct connection * c)
{
case LUA_OK:
{
+ // TODO: If keep-alive, then reset c->push?
plop_drop_thread(c->ref);
connection_free(c);
return 0;
@@ -255,7 +247,12 @@ int plop_handle_server(const int efd, const int server)
return -1;
}
+ connection->L = lua_newthread(plop.L);
+ if (NULL == connection->L)
+ return -1; // TODO: Revisit error handling.
+ connection->ref = luaL_ref(plop.L, LUA_REGISTRYINDEX);
connection->fd = client;
+ connection->push = 1;
e.data.ptr = connection;
if (-1 == epoll_ctl(efd, EPOLL_CTL_ADD, client, &e))