summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikail Bagishov <bagishov.mikail@yandex.ru>2020-07-05 23:36:35 +0300
committerMikail Bagishov <bagishov.mikail@yandex.ru>2020-07-26 23:19:57 +0300
commitcbcc42deb65ba306b7b78f9e896bbf41fff5672f (patch)
tree24a351ec31afcaf8a46fd52102e7a1dea0dc62d4
parent57b6bd77002830526b1a8160d7c499584d2d2a8b (diff)
downloadnix-cbcc42deb65ba306b7b78f9e896bbf41fff5672f.zip
Support nullable timeout in ppoll
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/poll.rs10
-rw-r--r--test/test_poll.rs4
3 files changed, 9 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d53b7f8e..785b0eb8 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<Infallible>` instead of `Result<Void>` (#[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 e276090e..be5bf224 100644
--- a/src/poll.rs
+++ b/src/poll.rs
@@ -130,16 +130,16 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result<libc::c_int> {
/// ([`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<libc::c_int> {
-
-
+pub fn ppoll(fds: &mut [PollFd], timeout: Option<TimeSpec>, sigmask: SigSet) -> Result<libc::c_int> {
+ 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 aef40e47..d1974acf 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));
}