diff options
author | Gregor Beck <gbeck@sernet.de> | 2013-09-19 15:14:25 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2013-12-11 22:46:09 +0100 |
commit | 8e44c2f96397a4f8cf945bcc810e3a1776d86a08 (patch) | |
tree | 642f1f2c122e49c306d1b2ccafa9fc53859371a5 /lib/tevent/tevent_queue.c | |
parent | 7a97d4c4c36d27e2c0732d70345d1766a4a86e94 (diff) | |
download | samba-8e44c2f96397a4f8cf945bcc810e3a1776d86a08.tar.gz samba-8e44c2f96397a4f8cf945bcc810e3a1776d86a08.tar.xz samba-8e44c2f96397a4f8cf945bcc810e3a1776d86a08.zip |
tevent: add tevent_queue_wait_send/recv()
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Gregor Beck <gbeck@sernet.de>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/tevent/tevent_queue.c')
-rw-r--r-- | lib/tevent/tevent_queue.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/tevent/tevent_queue.c b/lib/tevent/tevent_queue.c index 4750675802..361fc7bc2e 100644 --- a/lib/tevent/tevent_queue.c +++ b/lib/tevent/tevent_queue.c @@ -298,3 +298,55 @@ bool tevent_queue_running(struct tevent_queue *queue) { return queue->running; } + +struct tevent_queue_wait_state { + uint8_t dummy; +}; + +static void tevent_queue_wait_trigger(struct tevent_req *req, + void *private_data); + +struct tevent_req *tevent_queue_wait_send(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct tevent_queue *queue) +{ + struct tevent_req *req; + struct tevent_queue_wait_state *state; + bool ok; + + req = tevent_req_create(mem_ctx, &state, + struct tevent_queue_wait_state); + if (req == NULL) { + return NULL; + } + + ok = tevent_queue_add(queue, ev, req, + tevent_queue_wait_trigger, + NULL); + if (!ok) { + tevent_req_nomem(NULL, req); + return tevent_req_post(req, ev); + } + + return req; +} + +static void tevent_queue_wait_trigger(struct tevent_req *req, + void *private_data) +{ + tevent_req_done(req); +} + +bool tevent_queue_wait_recv(struct tevent_req *req) +{ + enum tevent_req_state state; + uint64_t err; + + if (tevent_req_is_error(req, &state, &err)) { + tevent_req_received(req); + return false; + } + + tevent_req_received(req); + return true; +} |