From e750e2b1eaf4b98a2870889cc100a150a1b09966 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 6 May 2014 09:39:01 +0200 Subject: [PATCH] messaging3: Fix messaging_filtered_read_send If we register an additional tevent context, we can now properly do nested event contexts, listening for just one message type inside a tevent_req_poll. At this point this only enhances things without ctdb, but I'm working fixing that soon. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- source3/lib/messages.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 6a08531f2a8..50c79a128d9 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -461,6 +461,7 @@ static struct messaging_rec *messaging_rec_dup(TALLOC_CTX *mem_ctx, struct messaging_filtered_read_state { struct tevent_context *ev; struct messaging_context *msg_ctx; + void *tevent_handle; bool (*filter)(struct messaging_rec *rec, void *private_data); void *private_data; @@ -492,6 +493,18 @@ struct tevent_req *messaging_filtered_read_send( state->private_data = private_data; /* + * We have to defer the callback here, as we might be called from + * within a different tevent_context than state->ev + */ + tevent_req_defer_callback(req, state->ev); + + state->tevent_handle = messaging_dgm_register_tevent_context( + state, msg_ctx, ev); + if (tevent_req_nomem(state, req)) { + return tevent_req_post(req, ev); + } + + /* * We add ourselves to the "new_waiters" array, not the "waiters" * array. If we are called from within messaging_read_done, * messaging_dispatch_rec will be in an active for-loop on @@ -529,6 +542,8 @@ static void messaging_filtered_read_cleanup(struct tevent_req *req, tevent_req_set_cleanup_fn(req, NULL); + TALLOC_FREE(state->tevent_handle); + /* * Just set the [new_]waiters entry to NULL, be careful not to mess * with the other "waiters" array contents. We are often called from -- 2.11.4.GIT