From e6e21ab0bb95fc3b4dff1f43730b03ac4ce685fb Mon Sep 17 00:00:00 2001 From: Mikail Bagishov Date: Sun, 5 Jul 2020 23:36:35 +0300 Subject: [PATCH] Support nullable timeout in ppoll --- src/poll.rs | 10 +++++++--- test/test_poll.rs | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/poll.rs b/src/poll.rs index e276090eb2..58d03e44c6 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -133,13 +133,17 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result { /// with the `sigmask` argument. /// #[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; + let timeout = match timeout { + Some(t) => t.as_ref(), + None => core::ptr::null() + }; 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)); }