From 686e0785ef6783977805caa30df60061ce638c23 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Mon, 3 Aug 2020 00:40:56 +0200 Subject: [PATCH] libipc now allows buffered readings in switched context. --- src/communication.c | 17 ++++++++++++++--- src/network.c | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/communication.c b/src/communication.c index bbb6a2c..148a8bc 100644 --- a/src/communication.c +++ b/src/communication.c @@ -496,7 +496,7 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i IPC_EVENT_CLEAN (event); - int32_t n; + int32_t n = 0; for (size_t i = 0; i < ctx->size; i++) { // We assume that any fd in the list has to be listen to. @@ -519,7 +519,18 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i gettimeofday(&tv_1, NULL); - if ((n = poll(ctx->pollfd, ctx->size, *timer)) < 0) { + int timer_ = *timer; + + /* In case there is a file descriptor that requires more to read. */ + for (size_t i = 0; i <= ctx->size; i++) { + if (ctx->cinfos[i].more_to_read == 1) { + // printf ("There is more to read for _at least_ fd %d\n", ctx->pollfd[i].fd); + timer_ = 0; + break; + } + } + + if ((n = poll(ctx->pollfd, ctx->size, timer_)) < 0) { IPC_RETURN_ERROR (IPC_ERROR_WAIT_EVENT__POLL); } @@ -538,7 +549,7 @@ struct ipc_error ipc_wait_event (struct ipc_ctx *ctx, struct ipc_event *event, i } // Timeout. - if (n == 0) { + if (n == 0 && timer_ != 0) { IPC_EVENT_SET (event, IPC_EVENT_TYPE_TIMER, 0, 0, NULL); IPC_RETURN_NO_ERROR; } diff --git a/src/network.c b/src/network.c index 1fa574c..bca2fe2 100644 --- a/src/network.c +++ b/src/network.c @@ -343,7 +343,7 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx // This is applied to protocol-specific messages, for example when the client // has to communicate with the proxy, not the service. if (r == IPC_CB_IGNORE) { - printf ("IGNORING REQUEST\n"); + // printf ("IGNORING REQUEST\n"); // In case of message reception: // 1. set event IPC_EVENT_TYPE_SWITCH, inform ipcd of a successful reception. IPC_EVENT_SET (event, IPC_EVENT_TYPE_SWITCH, index, ctx->pollfd[index].fd, NULL);