From 18fcb27ec91f27789270550a2a005cb773bf2fe0 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 22:53:25 +0100 Subject: The main event loop(s) now also catch an EINTR and return instead of blocking --- ot_event.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'ot_event.c') diff --git a/ot_event.c b/ot_event.c index ce0feef..1542bf5 100644 --- a/ot_event.c +++ b/ot_event.c @@ -83,8 +83,10 @@ int event_wait(ot_event *out, int max, int timeout_ms) { g_ready_space = max; } - while ((count = epoll_wait(g_epoll, g_ready, max, timeout_ms)) == -1 && errno == EINTR) - ; + /* An interrupted wait is reported as no events rather than retried here, + so that the caller gets to look at whatever the signal was about */ + if ((count = epoll_wait(g_epoll, g_ready, max, timeout_ms)) == -1) + return errno == EINTR ? 0 : -1; for (i = 0; i < count; ++i) { uint32_t events = g_ready[i].events; @@ -189,8 +191,10 @@ int event_wait(ot_event *out, int max, int timeout_ms) { deadline = &timeout; } - while ((count = kevent(g_kqueue, NULL, 0, g_ready, max, deadline)) == -1 && errno == EINTR) - ; + /* An interrupted wait is reported as no events rather than retried here, + so that the caller gets to look at whatever the signal was about */ + if ((count = kevent(g_kqueue, NULL, 0, g_ready, max, deadline)) == -1) + return errno == EINTR ? 0 : -1; for (i = 0; i < count; ++i) { uint64_t udata = (uint64_t)(uintptr_t)g_ready[i].udata; int eof = (g_ready[i].flags & (EV_EOF | EV_ERROR)) != 0; @@ -310,8 +314,10 @@ int event_del(int fd) { int event_wait(ot_event *out, int max, int timeout_ms) { int ready, found = 0, i; - while ((ready = poll(g_pfds, (nfds_t)g_count, timeout_ms)) == -1 && errno == EINTR) - ; + /* An interrupted wait is reported as no events rather than retried here, + so that the caller gets to look at whatever the signal was about */ + if ((ready = poll(g_pfds, (nfds_t)g_count, timeout_ms)) == -1) + return errno == EINTR ? 0 : -1; if (ready <= 0) return ready; -- cgit v1.3