aboutsummaryrefslogtreecommitdiff
path: root/handler.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-08-13 01:53:28 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-08-13 02:30:06 +0200
commit0e2f46e4887618ce45e979d939d1329312ecaacd (patch)
treee31ce8dd88d0343e4f12837535893a8daf43c13c /handler.c
parentf6562ddab30feb4bb63d9cda9801dbf607c33d07 (diff)
WIP parallelparallel
Diffstat (limited to 'handler.c')
-rw-r--r--handler.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/handler.c b/handler.c
index f29da15..2c63db8 100644
--- a/handler.c
+++ b/handler.c
@@ -4,6 +4,7 @@
#include "slweb/http.h"
#include "slweb/server.h"
#include "slweb/wildcard_cmp.h"
+#include <pthread.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
@@ -49,7 +50,8 @@ static int on_write(const void *const buf, const size_t n, void *const user)
}
static int on_payload(const struct http_payload *const p,
- struct http_response *const r, void *const user)
+ struct http_response *const r, struct http_future *const f,
+ void *const user)
{
struct client *const c = user;
struct handler *const h = c->h;
@@ -59,7 +61,7 @@ static int on_payload(const struct http_payload *const p,
const struct elem *const e = &h->elem[i];
if (e->op == p->op && !wildcard_cmp(p->resource, e->url, true))
- return e->f(p, r, e->user);
+ return e->f(p, r, f, e->user);
}
fprintf(stderr, "Not found: %s\n", p->resource);
@@ -72,6 +74,20 @@ static int on_payload(const struct http_payload *const p,
return 0;
}
+static void *async_start(void *const user)
+{
+ /* TOOD: call user callback. */
+ return NULL;
+}
+
+static int on_async(const struct http_future *const f, void *const user)
+{
+ struct client *const c = user;
+ struct handler *const h = c->h;
+
+ return server_async(h->server, f->f, f->user);
+}
+
static int on_length(const unsigned long long len,
const struct http_cookie *const c, struct http_response *const r,
void *const user)
@@ -107,6 +123,7 @@ static struct client *find_or_alloc_client(struct handler *const h,
.read = on_read,
.write = on_write,
.payload = on_payload,
+ .async = on_async,
.length = on_length,
.user = ret,
.tmpdir = h->cfg.tmpdir