1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-27 07:42:04 +03:00
Files
samba-mirror/source3/lib/unix_msg/test_source.c
Volker Lendecke dca572ff1c 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 <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
2014-05-08 09:10:12 +02:00

90 lines
1.7 KiB
C

#include "replace.h"
#include "unix_msg.h"
#include "poll_funcs/poll_funcs_tevent.h"
#include "tevent.h"
int main(int argc, const char *argv[])
{
struct poll_funcs *funcs;
void *tevent_handle;
struct unix_msg_ctx **ctxs;
struct tevent_context *ev;
struct iovec iov;
int ret;
unsigned i;
unsigned num_ctxs = 1;
if (argc < 2) {
fprintf(stderr, "Usage: %s <sockname> [num_contexts]\n", argv[0]);
return 1;
}
if (argc > 2) {
num_ctxs = atoi(argv[2]);
}
ev = tevent_context_init(NULL);
if (ev == NULL) {
perror("tevent_context_init failed");
return 1;
}
funcs = poll_funcs_init_tevent(NULL);
if (funcs == NULL) {
fprintf(stderr, "poll_funcs_init_tevent failed\n");
return 1;
}
tevent_handle = poll_funcs_tevent_register(NULL, funcs, ev);
if (tevent_handle == NULL) {
fprintf(stderr, "poll_funcs_tevent_register failed\n");
return 1;
}
ctxs = talloc_array(ev, struct unix_msg_ctx *, num_ctxs);
if (ctxs == NULL) {
fprintf(stderr, "talloc failed\n");
return 1;
}
for (i=0; i<num_ctxs; i++) {
ret = unix_msg_init(NULL, funcs, 256, 1, NULL, NULL,
&ctxs[i]);
if (ret != 0) {
fprintf(stderr, "unix_msg_init failed: %s\n",
strerror(ret));
return 1;
}
}
iov.iov_base = &i;
iov.iov_len = sizeof(i);
for (i=0; i<num_ctxs; i++) {
unsigned j;
for (j=0; j<100000; j++) {
ret = unix_msg_send(ctxs[i], argv[1], &iov, 1);
if (ret != 0) {
fprintf(stderr, "unix_msg_send failed: %s\n",
strerror(ret));
return 1;
}
}
}
while (true) {
ret = tevent_loop_once(ev);
if (ret == -1) {
fprintf(stderr, "tevent_loop_once failed: %s\n",
strerror(errno));
exit(1);
}
}
for (i=0; i<num_ctxs; i++) {
unix_msg_free(ctxs[i]);
}
talloc_free(ev);
return 0;
}