From be77188ec1db7e8ad39339a8d30597d5bd62987d Mon Sep 17 00:00:00 2001 From: Bryant Mairs Date: Thu, 23 Feb 2017 15:27:11 -0800 Subject: [PATCH] Add ppoll() --- src/poll.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/poll.rs b/src/poll.rs index 72988d8c3e..658e2e2b54 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,3 +1,6 @@ +use std; +use std::time::Duration; + use libc; use {Errno, Result}; @@ -47,3 +50,19 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result { Errno::result(res) } + +pub fn ppoll(fds: &mut [PollFd], timeout: Duration) -> Result { + + let timeout = libc::timespec { + tv_sec: timeout.as_secs() as libc::time_t, + tv_nsec: timeout.subsec_nanos() as libc::c_long, + }; + + let res = unsafe { + libc::ppoll(fds.as_mut_ptr() as *mut libc::pollfd, + fds.len() as libc::nfds_t, + &timeout as *const libc::timespec, + std::ptr::null()) + }; + Errno::result(res) +}