From d0e44deea801277ed970b17299675bf951d7d6d2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Thu, 29 Feb 2024 21:32:12 +0100 Subject: [PATCH] improve compatibility to the BSD socket layer `poll` should return 0, if the system call timed out --- src/fd/mod.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fd/mod.rs b/src/fd/mod.rs index 9f4646755d..b1951edc27 100644 --- a/src/fd/mod.rs +++ b/src/fd/mod.rs @@ -391,7 +391,17 @@ async fn poll_fds(fds: &mut [PollFd]) -> Result { /// monitored is specified in the `fds` argument, which is an array /// of structs of `PollFd`. pub fn poll(fds: &mut [PollFd], timeout: Option) -> Result { - block_on(poll_fds(fds), timeout) + let result = block_on(poll_fds(fds), timeout); + if let Err(ref e) = result { + if timeout.is_some() { + // A return value of zero indicates that the system call timed out + if *e == IoError::EAGAIN { + return Ok(0); + } + } + } + + result } /// `eventfd` creates an linux-like "eventfd object" that can be used