diff --git a/src/posix/poll.rs b/src/posix/poll.rs index e193ac0e..c4f2ccde 100644 --- a/src/posix/poll.rs +++ b/src/posix/poll.rs @@ -3,7 +3,7 @@ use std::io; use std::os::unix::io::RawFd; use std::slice; -use std::time::Duration; +use std::time::{Duration, Instant}; use nix::libc::c_int; use nix::poll::{PollFd, PollFlags}; @@ -24,14 +24,17 @@ fn wait_fd(fd: RawFd, events: PollFlags, timeout: Duration) -> io::Result<()> { use nix::errno::Errno::{EIO, EPIPE}; let mut fd = PollFd::new(fd, events); - - let wait = match poll_clamped(&mut fd, timeout) { - Ok(r) => r, - Err(e) => { - dbg!(e); - return Err(io::Error::from(crate::Error::from(e))); - } - }; + let end = Instant::now() + timeout; + let wait; + loop { + wait = match poll_clamped(&mut fd, end.saturating_duration_since(Instant::now())) { + Ok(r) => r, + Err(nix::Error::EINTR) => continue, + Err(nix::Error::EAGAIN) => continue, + Err(e) => return Err(io::Error::from(crate::Error::from(e))), + }; + break; + } // All errors generated by poll or ppoll are already caught by the nix wrapper around libc, so // here we only need to check if there's at least 1 event if wait != 1 {