ipc_connection now provides the server fd.
parent
b8c5c9d70e
commit
e147379f06
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in New Issue