diff --git a/src/device.rs b/src/device.rs index 4b62721..8c4c6f6 100644 --- a/src/device.rs +++ b/src/device.rs @@ -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 { - 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) + } } } }