Skip to content

Commit

Permalink
Merge #1270
Browse files Browse the repository at this point in the history
1270: Support nullable timeout in ppoll r=asomers a=MikailBag



Co-authored-by: Mikail Bagishov <bagishov.mikail@yandex.ru>
  • Loading branch information
bors[bot] and MikailBag authored Jul 26, 2020
2 parents 557a8fe + cbcc42d commit 2a668fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/test_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

0 comments on commit 2a668fa

Please sign in to comment.