diff options
Diffstat (limited to 'connection.c')
-rw-r--r-- | connection.c | 23 |
1 files changed, 9 insertions, 14 deletions
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); } |