From dca572ff1ce1559a2254d9ba46d4f86d48c38c21 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 5 May 2014 08:45:52 +0200 Subject: lib: Enhance poll_funcs_tevent for multiple tevent_contexts With this patch it will be possible to use nested event contexts with messaging_filtered_read_send/recv. Before this patchset only the one and only event context a messaging_context is initialized with is able to receive datagrams from the unix domain socket. So if you want to code a synchronous RPC-like operation using a nested event context, you will not see the reply, because the nested event context does not have the required tevent_fd's. Unfortunately, this patchset has to add some advanced array voodoo. The idea is that state->watches[] contains what we hand out with watch_new, and state->contexts contains references to the tevent_contexts. For every watch we need a tevent_fd in every event context, and the routines make sure that the arrays are properly maintained. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- source3/lib/unix_msg/tests.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'source3/lib/unix_msg/tests.c') diff --git a/source3/lib/unix_msg/tests.c b/source3/lib/unix_msg/tests.c index 2a4cf86234..29d5dcb374 100644 --- a/source3/lib/unix_msg/tests.c +++ b/source3/lib/unix_msg/tests.c @@ -32,7 +32,8 @@ static void expect_messages(struct tevent_context *ev, struct cb_state *state, int main(void) { - struct poll_funcs funcs; + struct poll_funcs *funcs; + void *tevent_handle; const char *sock1 = "sock1"; const char *sock2 = "sock2"; struct unix_msg_ctx *ctx1, *ctx2; @@ -52,9 +53,19 @@ int main(void) perror("tevent_context_init failed"); return 1; } - poll_funcs_init_tevent(&funcs, ev); - ret = unix_msg_init(sock1, &funcs, 256, 1, + funcs = poll_funcs_init_tevent(ev); + if (funcs == NULL) { + fprintf(stderr, "poll_funcs_init_tevent failed\n"); + return 1; + } + tevent_handle = poll_funcs_tevent_register(ev, funcs, ev); + if (tevent_handle == NULL) { + fprintf(stderr, "poll_funcs_register_tevent failed\n"); + return 1; + } + + ret = unix_msg_init(sock1, funcs, 256, 1, recv_cb, &state, &ctx1); if (ret != 0) { fprintf(stderr, "unix_msg_init failed: %s\n", @@ -62,7 +73,7 @@ int main(void) return 1; } - ret = unix_msg_init(sock1, &funcs, 256, 1, + ret = unix_msg_init(sock1, funcs, 256, 1, recv_cb, &state, &ctx1); if (ret == 0) { fprintf(stderr, "unix_msg_init succeeded unexpectedly\n"); @@ -74,7 +85,7 @@ int main(void) return 1; } - ret = unix_msg_init(sock2, &funcs, 256, 1, + ret = unix_msg_init(sock2, funcs, 256, 1, recv_cb, &state, &ctx2); if (ret != 0) { fprintf(stderr, "unix_msg_init failed: %s\n", @@ -201,6 +212,8 @@ int main(void) unix_msg_free(ctx1); unix_msg_free(ctx2); + talloc_free(tevent_handle); + talloc_free(funcs); talloc_free(ev); return 0; -- cgit