#include "connection.h" #include #include #include #include #include /// Creates new connection. /// \param L Server's Lua state /// \param client File descriptor of client's socket /// \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) { return NULL; } memset(c, 0, sizeof(struct connection)); c->fd = client; c->ref = LUA_NOREF; c->L = NULL; return c; } /// 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) { if (LUA_NOREF != c->ref) { luaL_unref(L, LUA_REGISTRYINDEX, c->ref); } close(c->fd); // TODO: Check for errors in close()? free(c); }