diff --git a/CHANGELOG.md b/CHANGELOG.md index d53b7f8e95..785b0eb885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Changed `fallocate` return type from `c_int` to `()` (#[1201](https://github.com/nix-rust/nix/pull/1201)) - Enabled `sys::ptrace::setregs` and `sys::ptrace::getregs` on x86_64-unknown-linux-musl target (#[1198](https://github.com/nix-rust/nix/pull/1198)) -- On Linux, `ptrace::write` is now an `unsafe` function. Caveat programmer. +- On Linux, `ptrace::write` is now an `unsafe` function. Caveat programmer. (#[1245](https://github.com/nix-rust/nix/pull/1245)) - `execv`, `execve`, `execvp` and `execveat` in `::nix::unistd` and `reboot` in `::nix::sys::reboot` now return `Result` instead of `Result` (#[1239](https://github.com/nix-rust/nix/pull/1239)) @@ -61,6 +61,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). (#[1244](https://github.com/nix-rust/nix/pull/1244)) - Several `Inotify` methods now take `self` by value instead of by reference (#[1244](https://github.com/nix-rust/nix/pull/1244)) +- `nix::poll::ppoll`: `timeout` parameter is now optional, None is equivalent for infinite timeout. ### Fixed diff --git a/src/poll.rs b/src/poll.rs index e276090eb2..be5bf22499 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -130,16 +130,16 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result { /// ([`poll(2)`](http://man7.org/linux/man-pages/man2/poll.2.html)) /// /// `ppoll` behaves like `poll`, but let you specify what signals may interrupt it -/// with the `sigmask` argument. +/// with the `sigmask` argument. If you want `ppoll` to block indefinitely, +/// specify `None` as `timeout` (it is like `timeout = -1` for `poll`). /// #[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))] -pub fn ppoll(fds: &mut [PollFd], timeout: TimeSpec, sigmask: SigSet) -> Result { - - +pub fn ppoll(fds: &mut [PollFd], timeout: Option, sigmask: SigSet) -> Result { + let timeout = timeout.as_ref().map_or(core::ptr::null(), |r| r.as_ref()); let res = unsafe { libc::ppoll(fds.as_mut_ptr() as *mut libc::pollfd, fds.len() as libc::nfds_t, - timeout.as_ref(), + timeout, sigmask.as_ref()) }; Errno::result(res) diff --git a/test/test_poll.rs b/test/test_poll.rs index aef40e4792..d1974acfc6 100644 --- a/test/test_poll.rs +++ b/test/test_poll.rs @@ -37,14 +37,14 @@ fn test_ppoll() { let mut fds = [PollFd::new(r, PollFlags::POLLIN)]; // Poll an idle pipe. Should timeout - let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap(); + let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap(); assert_eq!(nfds, 0); assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN)); write(w, b".").unwrap(); // Poll a readable pipe. Should return an event. - let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap(); + let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap(); assert_eq!(nfds, 1); assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN)); }