Skip to content

Commit c17d5b3

Browse files
luca-barbiericarllerche
authored andcommitted
sys/event: add kevent_ts to better expose kevent timeout
This allows to specify no timeout and allows to specify any timespec timeout.
1 parent 5ef1f7a commit c17d5b3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/sys/event.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use {Error, Result};
55
use errno::Errno;
66
use libc::{timespec, time_t, c_int, c_long, uintptr_t};
77
use std::os::unix::io::RawFd;
8+
use std::ptr;
89

910
pub use self::ffi::kevent as KEvent;
1011

@@ -214,14 +215,21 @@ pub fn kevent(kq: RawFd,
214215
tv_nsec: ((timeout_ms % 1000) * 1_000_000) as c_long
215216
};
216217

218+
kevent_ts(kq, changelist, eventlist, Some(timeout))
219+
}
220+
221+
pub fn kevent_ts(kq: RawFd,
222+
changelist: &[KEvent],
223+
eventlist: &mut [KEvent],
224+
timeout_opt: Option<timespec>) -> Result<usize> {
217225
let res = unsafe {
218226
ffi::kevent(
219227
kq,
220228
changelist.as_ptr(),
221229
changelist.len() as c_int,
222230
eventlist.as_mut_ptr(),
223231
eventlist.len() as c_int,
224-
&timeout as *const timespec)
232+
if let Some(ref timeout) = timeout_opt {timeout as *const timespec} else {ptr::null()})
225233
};
226234

227235
if res < 0 {

0 commit comments

Comments
 (0)