From 4fdf60a4c9ce16dd459e05ad7664010ea45c43db Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Feb 2021 01:04:57 +0100 Subject: Started progress towards coroutine-based connection handling --- connection.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'connection.c') diff --git a/connection.c b/connection.c index f987d65..055b498 100644 --- a/connection.c +++ b/connection.c @@ -15,6 +15,8 @@ /// \return Pointer to connection or NULL if an error occured struct connection * connection_new(lua_State * L, const int client) { + (void) L; // TODO: Review if lua_State is still needed for connections and server handler. + struct connection * c = malloc(sizeof(struct connection)); if (NULL == c) @@ -25,29 +27,22 @@ struct connection * connection_new(lua_State * L, const int client) memset(c, 0, sizeof(struct connection)); c->fd = client; - c->L = lua_newthread(L); - c->lua_ref = luaL_ref(L, LUA_REGISTRYINDEX); + c->ref = LUA_NOREF; + c->L = NULL; return c; } -/// Clears the state of connection readying it for new request. -/// \param c Connection to clear -void connection_clear(struct connection * c) -{ - if (NULL != c->request) - { - free_request(c->request); - } -} - /// Frees all resources associated with the connection. /// \param L Server's Lua state /// \param c Connection to free void connection_free(lua_State * L, struct connection * c) { - connection_clear(c); - luaL_unref(L, LUA_REGISTRYINDEX, c->lua_ref); + if (LUA_NOREF != c->ref) + { + luaL_unref(L, LUA_REGISTRYINDEX, c->ref); + } + close(c->fd); // TODO: Check for errors in close()? free(c); } -- cgit v1.1