messaging3: Fix messaging_filtered_read_send
authorVolker Lendecke <vl@samba.org>
Tue, 6 May 2014 07:39:01 +0000 (09:39 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 8 May 2014 07:10:12 +0000 (09:10 +0200)
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 <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages.c

index 6a08531f2a86356e9ae63dc2451def8795c931de..50c79a128d987bc659cd746aab04bd91cbee38cf 100644 (file)
@@ -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;
@@ -491,6 +492,18 @@ struct tevent_req *messaging_filtered_read_send(
        state->filter = filter;
        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,
@@ -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