kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit d8508f4a7b4af57dd0e4747a3ae1ab97cdd7bc84
parent cf94a53be7d7aa79fb6693cabb6b610fc60df70f
Author: Joris Vink <joris@coders.se>
Date:   Wed,  1 Jul 2015 11:03:54 +0200

Add the actual task changes for last commit.

Diffstat:
examples/pipe_task/README.md | 6+++---
includes/tasks.h | 3+++
src/tasks.c | 16++++++++++++++++
3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/examples/pipe_task/README.md b/examples/pipe_task/README.md @@ -18,8 +18,8 @@ Test: Hit the connect button to open a websocket session. - Now connect a writer endpoint to the named pipe (/tmp/pipe), a great - test is tcpdump, you should see all output scroll on the browser. + Now connect a writer endpoint to the named pipe (/tmp/pipe): + $ echo "hello" > /tmp/pipe - # tcpdump -l -i interface -n > /tmp/pipe + You should see the result in your browser. ``` diff --git a/includes/tasks.h b/includes/tasks.h @@ -41,6 +41,7 @@ struct kore_task { struct http_request *req; int fds[2]; int (*entry)(struct kore_task *); + void (*cb)(struct kore_task *); struct kore_task_thread *thread; @@ -67,6 +68,8 @@ void kore_task_handle(struct kore_task *, int); void kore_task_bind_request(struct kore_task *, struct http_request *); +void kore_task_bind_callback(struct kore_task *, + void (*cb)(struct kore_task *)); void kore_task_create(struct kore_task *, int (*entry)(struct kore_task *)); diff --git a/src/tasks.c b/src/tasks.c @@ -55,6 +55,7 @@ kore_task_init(void) void kore_task_create(struct kore_task *t, int (*entry)(struct kore_task *)) { + t->cb = NULL; t->req = NULL; t->entry = entry; t->type = KORE_TYPE_TASK; @@ -95,6 +96,9 @@ kore_task_bind_request(struct kore_task *t, struct http_request *req) { kore_debug("kore_task_bind_request: %p bound to %p", req, t); + if (t->cb != NULL) + fatal("cannot bind cbs and requests at the same time"); + t->req = req; LIST_INSERT_HEAD(&(req->tasks), t, rlist); @@ -102,6 +106,15 @@ kore_task_bind_request(struct kore_task *t, struct http_request *req) } void +kore_task_bind_callback(struct kore_task *t, void (*cb)(struct kore_task *)) +{ + if (t->req != NULL) + fatal("cannot bind requests and cbs at the same time"); + + t->cb = cb; +} + +void kore_task_destroy(struct kore_task *t) { kore_debug("kore_task_destroy: %p", t); @@ -196,6 +209,9 @@ kore_task_handle(struct kore_task *t, int finished) kore_task_destroy(t); } } + + if (t->cb != NULL) + t->cb(t); } int