summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-02-24 20:58:58 +0100
committerAki <please@ignore.pl>2021-02-24 20:58:58 +0100
commitd6a54f904957d34f12361d5d8a7e515562cda3d5 (patch)
tree4f132f4bd0eb0058243995b44cec52d633cc0fcc
parentd46748ac59c3b8d8895d2671aa4b1eca3914d1d4 (diff)
downloadplop-d6a54f904957d34f12361d5d8a7e515562cda3d5.zip
plop-d6a54f904957d34f12361d5d8a7e515562cda3d5.tar.gz
plop-d6a54f904957d34f12361d5d8a7e515562cda3d5.tar.bz2
Readded response for this time being
-rw-r--r--Makefile3
-rw-r--r--default.lua2
-rw-r--r--plop.c14
3 files changed, 16 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 68c7d65..26bb34c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,12 +5,13 @@ LDLIBS+=-llua5.3
PREFIX?=/usr/local
SHARE?=$(PREFIX)/share
-plop: connection.o main.o plop.o stream.o
+plop: connection.o main.o plop.o stream.o response.o
main.o: plop.h
plop.o: connection.h plop.h stream.h
connection.o: connection.h
stream.o: stream.h
+response.o: response.h
clean:
rm -f plop *.o
diff --git a/default.lua b/default.lua
index 95ba609..dc4237e 100644
--- a/default.lua
+++ b/default.lua
@@ -1,6 +1,6 @@
--- Default client request handler.
-- TODO: Add documentation once request and response API are more stable.
-return function (method, path, version, headers, data)
+return function (stream)
local response_data = [["Hello from plop/lua!"]]
local headers = {Connection="close", ["Content-Length"]=#response_data, ["Content-Type"]="application/json"}
return {status=200, headers=headers, data=response_data}
diff --git a/plop.c b/plop.c
index 980ce90..7859e7b 100644
--- a/plop.c
+++ b/plop.c
@@ -17,6 +17,7 @@
#include "connection.h"
#include "stream.h"
+#include "response.h"
/// Initializes new Lua state for the server.
/// \return Lua state
@@ -158,20 +159,31 @@ int plop_handle_client(lua_State * L, struct epoll_event * event)
}
int result = lua_resume(c->L, NULL, nargs);
- connection_free(L, c); // TODO: Allow consistent connections?
switch (result)
{
case LUA_OK:
{
+ int n = lua_gettop(c->L);
+
+ if (0 == n)
+ {
+ lua_pushnil(c->L);
+ }
+
+ response_send(c->L, c->fd);
+ connection_free(L, c);
+
return 0;
}
case LUA_YIELD:
{
+ connection_free(L, c); // TODO: This shouldn't be the case... Right?
return 0;
}
default:
{
+ connection_free(L, c);
return -1;
}
}