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

device: Retry poll() on interrupts (EINTR) #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
44 changes: 26 additions & 18 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,24 +382,32 @@ impl Handle {
/// A value of zero returns immedately, even if the fd is not ready.
/// A negative value means infinite timeout (blocking).
pub fn poll(&self, events: i16, timeout: i32) -> io::Result<i32> {
match unsafe {
libc::poll(
[libc::pollfd {
fd: self.fd,
events,
revents: 0,
}]
.as_mut_ptr(),
1,
timeout,
)
} {
-1 => Err(io::Error::last_os_error()),
ret => {
// A return value of zero means that we timed out. A positive value signifies the
// number of fds with non-zero revents fields (aka I/O activity).
assert!(ret == 0 || ret == 1);
Ok(ret)
loop {
return match unsafe {
libc::poll(
[libc::pollfd {
fd: self.fd,
events,
revents: 0,
}]
.as_mut_ptr(),
1,
timeout,
)
} {
-1 => {
let e = io::Error::last_os_error();
match e.kind() {
io::ErrorKind::Interrupted => continue,
_ => Err(e),
}
},
ret => {
// A return value of zero means that we timed out. A positive value signifies the
// number of fds with non-zero revents fields (aka I/O activity).
assert!(ret == 0 || ret == 1);
Ok(ret)
}
}
}
}
Expand Down