From c585f01f4d13a25edb62477c07fdf32451417fee Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Thu, 29 Dec 2022 10:14:41 +0100 Subject: [PATCH] Allow system suspension while polling events If the system suspend and wake up while we are epoll pwaiting, linux return an error code EINTR. We ignore this issue specificely to allow ev programs to continue after wakeups. Signed-off-by: Stacy Harper --- ev/+linux/loop.ha | 15 +++++++++++++-- diff --git a/ev/+linux/loop.ha b/ev/+linux/loop.ha index 887e62d73a646292b555fe63def83b279f39e8cf..aec5cc0065c8ce74cf146291a45d5a12f3ce1184 100644 --- a/ev/+linux/loop.ha +++ b/ev/+linux/loop.ha @@ -76,9 +76,20 @@ // TODO: Deal with signals const maxev = len(loop.events); assert(maxev <= types::INT_MAX: size, "ev::dispatch: too many events"); - const nevent = rt::epoll_pwait( + const nevent = match(rt::epoll_pwait( loop.fd, &loop.events[0], - maxev: int, millis, null)!; + maxev: int, millis, null)) { + case let nevent: int => + yield nevent; + case let err: rt::errno => + switch (err) { + case rt::EINTR => + // We shallow system suspension error code + return true; + case => + abort("ev::dispatch: epoll_pwait failure"); + }; + }; for (let i = 0; i < nevent; i += 1) { const ev = &loop.events[i]; -- 2.48.1