Skip to content

Commit e6e21ab

Browse files
committed
Support nullable timeout in ppoll
1 parent a777389 commit e6e21ab

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/poll.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,17 @@ pub fn poll(fds: &mut [PollFd], timeout: libc::c_int) -> Result<libc::c_int> {
133133
/// with the `sigmask` argument.
134134
///
135135
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
136-
pub fn ppoll(fds: &mut [PollFd], timeout: TimeSpec, sigmask: SigSet) -> Result<libc::c_int> {
137-
136+
pub fn ppoll(fds: &mut [PollFd], timeout: Option<TimeSpec>, sigmask: SigSet) -> Result<libc::c_int> {
137+
let timeout = &timeout;
138+
let timeout = match timeout {
139+
Some(t) => t.as_ref(),
140+
None => core::ptr::null()
141+
};
138142

139143
let res = unsafe {
140144
libc::ppoll(fds.as_mut_ptr() as *mut libc::pollfd,
141145
fds.len() as libc::nfds_t,
142-
timeout.as_ref(),
146+
timeout,
143147
sigmask.as_ref())
144148
};
145149
Errno::result(res)

test/test_poll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ fn test_ppoll() {
3737
let mut fds = [PollFd::new(r, PollFlags::POLLIN)];
3838

3939
// Poll an idle pipe. Should timeout
40-
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
40+
let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap();
4141
assert_eq!(nfds, 0);
4242
assert!(!fds[0].revents().unwrap().contains(PollFlags::POLLIN));
4343

4444
write(w, b".").unwrap();
4545

4646
// Poll a readable pipe. Should return an event.
47-
let nfds = ppoll(&mut fds, timeout, SigSet::empty()).unwrap();
47+
let nfds = ppoll(&mut fds, Some(timeout), SigSet::empty()).unwrap();
4848
assert_eq!(nfds, 1);
4949
assert!(fds[0].revents().unwrap().contains(PollFlags::POLLIN));
5050
}

0 commit comments

Comments
 (0)