From e147379f060cd54a4d8ffaf1f74fb2fe02c599ce Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 13 Jul 2020 18:37:33 +0200 Subject: [PATCH] ipc_connection now provides the server fd. --- examples/pong.c | 4 ++-- examples/pongspam.c | 4 ++-- examples/simple-tcpd.c | 5 +---- examples/test-networkd-provide-fd.c | 2 +- examples/wsserver.c | 2 +- src/communication.c | 4 ++-- src/ipc.h | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/examples/pong.c b/examples/pong.c index 6b738cc..a1687c1 100644 --- a/examples/pong.c +++ b/examples/pong.c @@ -30,7 +30,7 @@ void non_interactive (int verbosity, size_t nb_msg, char *msg_str) SECURE_DECLARATION (struct ipc_message, m); // init service - TEST_IPC_QUIT_ON_ERROR (ipc_connection (ctx, SERVICE_NAME), EXIT_FAILURE); + TEST_IPC_QUIT_ON_ERROR (ipc_connection (ctx, SERVICE_NAME, NULL), EXIT_FAILURE); if (verbosity > 1) { printf ("msg to send (%ld): %.*s\n", (ssize_t) strlen (MSG) + 1, (int)strlen (MSG), MSG); @@ -54,7 +54,7 @@ void non_interactive (int verbosity, size_t nb_msg, char *msg_str) void interactive () { // init service - TEST_IPC_QUIT_ON_ERROR (ipc_connection (ctx, SERVICE_NAME), EXIT_FAILURE); + TEST_IPC_QUIT_ON_ERROR (ipc_connection (ctx, SERVICE_NAME, NULL), EXIT_FAILURE); SECURE_DECLARATION (struct ipc_error, ret); SECURE_DECLARATION (struct ipc_event, event); diff --git a/examples/pongspam.c b/examples/pongspam.c index 2f9cb42..5a268cd 100644 --- a/examples/pongspam.c +++ b/examples/pongspam.c @@ -30,7 +30,7 @@ void non_interactive () SECURE_DECLARATION (struct ipc_message, m); // init service - TEST_IPC_Q (ipc_connection (ctx, SERVICE_NAME), EXIT_FAILURE); + TEST_IPC_Q (ipc_connection (ctx, SERVICE_NAME, NULL), EXIT_FAILURE); TEST_IPC_Q (ipc_message_format_data (&m, 42, MSG, (ssize_t) strlen (MSG) + 1), EXIT_FAILURE); printf ("msg to send (%ld): %.*s\n", (ssize_t) strlen (MSG) + 1, (int)strlen (MSG), MSG); @@ -48,7 +48,7 @@ void non_interactive () void interactive () { // init service - TEST_IPC_Q (ipc_connection (ctx, SERVICE_NAME), EXIT_FAILURE); + TEST_IPC_Q (ipc_connection (ctx, SERVICE_NAME, NULL), EXIT_FAILURE); SECURE_DECLARATION (struct ipc_event, event); diff --git a/examples/simple-tcpd.c b/examples/simple-tcpd.c index 1811021..66cb268 100644 --- a/examples/simple-tcpd.c +++ b/examples/simple-tcpd.c @@ -90,14 +90,11 @@ void tcp_connection (int fd) T_PERROR_Q ((send (fd, "OK", 2, 0) <= 0), "sending a message", EXIT_FAILURE); printf ("connection to %s\n", buf); - struct ipc_error ret = ipc_connection_switched (ctx, buf); + struct ipc_error ret = ipc_connection_switched (ctx, buf, fd, NULL); if (ret.error_code != IPC_ERROR_NONE) { fprintf (stderr, "%s\n", ret.error_message); exit (EXIT_FAILURE); } - - ipc_switching_add (&ctx->switchdb, fd, ctx->pollfd[ctx->size-1].fd); - ipc_ctx_fd_type (ctx, fd, IPC_CONNECTION_TYPE_SWITCHED); } int accept_new_client (int serverfd) diff --git a/examples/test-networkd-provide-fd.c b/examples/test-networkd-provide-fd.c index 077a288..769736a 100644 --- a/examples/test-networkd-provide-fd.c +++ b/examples/test-networkd-provide-fd.c @@ -26,7 +26,7 @@ int main (void) /** TODO: contact the service */ printf ("WARNING: currently this program only ask for pong service %d\n", ret.error_code); - TEST_IPC_Q (ipc_connection (&ctx, "pong"), EXIT_FAILURE); + TEST_IPC_Q (ipc_connection (&ctx, "pong", NULL), EXIT_FAILURE); ipc_provide_fd (client_fd, ctx.pollfd[ctx.size-1].fd); diff --git a/examples/wsserver.c b/examples/wsserver.c index 9a2dd0a..12cb3fd 100644 --- a/examples/wsserver.c +++ b/examples/wsserver.c @@ -38,7 +38,7 @@ void interactive () } // init service - TEST_IPC_Q (ipc_connection (ctx, service_name), EXIT_FAILURE); + TEST_IPC_Q (ipc_connection (ctx, service_name, NULL), EXIT_FAILURE); ipc_add_fd (ctx, 0); // add STDIN diff --git a/src/communication.c b/src/communication.c index a686e61..9490840 100644 --- a/src/communication.c +++ b/src/communication.c @@ -151,10 +151,10 @@ int ipc_ctx_fd_type (struct ipc_ctx *ctx, int fd, enum ipc_connection_type type) return -1; } -struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname) +struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname, int *serverfd) { // Data received on the socket = messages, not new clients, and not switched (no callbacks). - return ipc_connection_ (ctx, sname, IPC_CONNECTION_TYPE_IPC, NULL); + return ipc_connection_ (ctx, sname, IPC_CONNECTION_TYPE_IPC, serverfd); } struct ipc_error ipc_connection_switched (struct ipc_ctx *ctx, const char *sname, int clientfd, int *serverfd) diff --git a/src/ipc.h b/src/ipc.h index 898d852..9856311 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -329,7 +329,7 @@ struct ipc_event { struct ipc_error ipc_wait_event (struct ipc_ctx *, struct ipc_event *, int *timer); struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname); -struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname); +struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname, int *fd); struct ipc_error ipc_connection_switched (struct ipc_ctx *ctx, const char *sname, int clientfd, int *serverfd); struct ipc_error ipc_close (struct ipc_ctx *ctx, uint32_t index);