Skip to content
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