summaryrefslogtreecommitdiffhomepage
path: root/plop.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-02-13 02:19:57 +0100
committerAki <please@ignore.pl>2021-02-13 02:19:57 +0100
commit29693b1880010578d3716c4ac4a43b3da9f0a4d3 (patch)
tree3e6a7e5bb2790a4f48d0e04d4c349c677d270157 /plop.c
parentc47d4b2314b06f28cae47d4dd14ef4c9c5c1af60 (diff)
downloadplop-29693b1880010578d3716c4ac4a43b3da9f0a4d3.zip
plop-29693b1880010578d3716c4ac4a43b3da9f0a4d3.tar.gz
plop-29693b1880010578d3716c4ac4a43b3da9f0a4d3.tar.bz2
Moved plop to use connection instead of just request
Diffstat (limited to 'plop.c')
-rw-r--r--plop.c41
1 files changed, 16 insertions, 25 deletions
diff --git a/plop.c b/plop.c
index b1c5944..c64ad11 100644
--- a/plop.c
+++ b/plop.c
@@ -14,6 +14,7 @@
#include <lauxlib.h>
#include <lua.h>
+#include "connection.h"
#include "request.h"
#include "response.h"
@@ -121,34 +122,25 @@ int plop_load_handler(lua_State * L, const char * path)
/// \return -1 if an error occured
int plop_handle_client(lua_State * L, struct epoll_event * event)
{
- // TODO: Temporary shenanigans to avoid too much changes.
- struct request * r = (struct request *) event->data.ptr;
- struct request ** request = &r;
+ struct connection * connection = (struct connection *) event->data.ptr;
- if (-1 == parse_request(L, (*request)->fd, request))
+ if (-1 == parse_request(connection))
{
- lua_newtable((*request)->lua);
- lua_pushstring((*request)->lua, "status");
- lua_pushinteger((*request)->lua, 400); // TODO: How about a function that generates error responses?
- lua_rawset((*request)->lua, -3);
+ lua_newtable(connection->L);
+ lua_pushstring(connection->L, "status");
+ lua_pushinteger(connection->L, 400); // TODO: How about a function that generates error responses?
+ lua_rawset(connection->L, -3);
}
else // TODO: 0 may mean EAGAIN, stuff will be bad very soon from here.
{
// TODO: Push the handler to stack earlier to avoid shifting it.
- lua_getglobal((*request)->lua, "handler");
- lua_insert((*request)->lua, 1);
- lua_call((*request)->lua, 5, 1);
+ lua_getglobal(connection->L, "handler");
+ lua_insert(connection->L, 1);
+ lua_call(connection->L, 5, 1);
}
- int result = response_send((*request)->lua, (*request)->fd);
-
- close((*request)->fd);
-
- if (NULL != *request)
- {
- free_request(L, *request);
- *request = NULL;
- }
+ int result = response_send(connection->L, connection->fd);
+ connection_free(L, connection);
return result;
}
@@ -201,15 +193,14 @@ int plop_handle_server(lua_State * L, const int efd, const int server)
return 0; // TODO: Retriage this error at some point.
}
- // TODO: Request is not the enitre state of the client. Make them distinct along with responses.
- struct request * request = new_request(L);
- if (NULL == request)
+ struct connection * connection = connection_new(L, client);
+ if (NULL == connection)
{
return -1;
}
- request->fd = client;
- e.data.ptr = request;
+ connection->fd = client;
+ e.data.ptr = connection;
if (-1 == epoll_ctl(efd, EPOLL_CTL_ADD, client, &e))
{