From c2aa94716f2d5446aafb60ddb50427c776db9cf2 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 14 Jul 2020 16:10:18 +0200 Subject: [PATCH] adding ipc_read_fd --- src/communication.c | 9 +++++++-- src/ipc.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/communication.c b/src/communication.c index 9490840..bbdd3a6 100644 --- a/src/communication.c +++ b/src/communication.c @@ -261,7 +261,7 @@ struct ipc_error ipc_accept_add (struct ipc_event *event, struct ipc_ctx *ctx, u } // receive then format in an ipc_message structure -struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc_message *m) +struct ipc_error ipc_read_fd (int32_t fd, struct ipc_message *m) { T_R ((m == NULL), IPC_ERROR_READ__NO_MESSAGE_PARAM); @@ -270,12 +270,17 @@ struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc char *pbuf = buf; // On error or closed recipient, the buffer already freed. - TEST_IPC_RETURN_ON_ERROR (usock_recv (ctx->pollfd[index].fd, &pbuf, &msize)); + TEST_IPC_RETURN_ON_ERROR (usock_recv (fd, &pbuf, &msize)); TEST_IPC_RETURN_ON_ERROR (ipc_message_format_read (m, buf, msize)); IPC_RETURN_NO_ERROR; // propagates ipc_message_format return } +struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc_message *m) +{ + return ipc_read_fd (ctx->pollfd[index].fd, m); +} + struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m) { size_t msize = 0; diff --git a/src/ipc.h b/src/ipc.h index 9856311..05ab2f9 100644 --- a/src/ipc.h +++ b/src/ipc.h @@ -337,7 +337,8 @@ struct ipc_error ipc_close_all (struct ipc_ctx *ctx); void ipc_ctx_free (struct ipc_ctx *ctx); -struct ipc_error ipc_read (const struct ipc_ctx *, uint32_t index, struct ipc_message *m); +struct ipc_error ipc_read (const struct ipc_ctx *, uint32_t index, struct ipc_message *m); +struct ipc_error ipc_read_fd (int32_t fd, struct ipc_message *m); struct ipc_error ipc_write (struct ipc_ctx *, const struct ipc_message *m); struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx, int index);