Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry poll on EINTR/EAGAIN instead of debug printing #215

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/posix/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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 {
Expand Down
Loading