From db1b27d8332cf55be1ca1d1ebbbfd96dace67529 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Sun, 1 Oct 2017 11:12:19 +0200 Subject: [PATCH] Provide EV_SET along with a number of helper types for kqueue/kevent --- libc-test/build.rs | 4 +++ src/unix/bsd/apple/mod.rs | 16 ++++++++++++ src/unix/bsd/freebsdlike/mod.rs | 16 ++++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 30 +++++++++++++++++----- src/unix/bsd/netbsdlike/openbsdlike/mod.rs | 16 ++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 95ffebb9e5739..69eeea5370ea6 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -348,6 +348,10 @@ fn main() { // sighandler_t is crazy across platforms "sighandler_t" => true, + // These types aren't actually defined on the platform, + // they simplify working with kqueue across BSD variants + ty if ty.starts_with("kevent_") => true, + _ => false } }); diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 6407e77bf3bda..4948b3b65eda5 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -23,6 +23,10 @@ pub type nl_item = ::c_int; pub type id_t = ::c_uint; pub type sem_t = ::c_int; pub type idtype_t = ::c_uint; +pub type kevent_nevents = ::c_int; +pub type kevent_filter = ::int16_t; +pub type kevent_flags = ::uint16_t; +pub type kevent_fflags = ::uint32_t; pub enum timezone {} @@ -1969,6 +1973,18 @@ f! { pub fn WIFSTOPPED(status: ::c_int) -> bool { _WSTATUS(status) == _WSTOPPED && WSTOPSIG(status) != 0x13 } + + pub fn EV_SET(ident: ::uintptr_t, filter: kevent_filter, flags: kevent_flags, + fflags: kevent_fflags, data: i64, udata: isize) -> kevent { + kevent { + ident: ident, + filter: filter, + flags: flags, + fflags: fflags, + data: data as ::intptr_t, + udata: udata as *mut ::c_void, + } + } } extern { diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 8cc87ce9f52ba..3d0a76b5ace6f 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -13,6 +13,10 @@ pub type tcflag_t = ::c_uint; pub type speed_t = ::c_uint; pub type nl_item = ::c_int; pub type id_t = i64; +pub type kevent_nevents = ::c_int; +pub type kevent_filter = ::c_short; +pub type kevent_flags = ::c_ushort; +pub type kevent_fflags = ::c_uint; pub enum timezone {} @@ -952,6 +956,18 @@ f! { pub fn WIFSTOPPED(status: ::c_int) -> bool { (status & 0o177) == 0o177 } + + pub fn EV_SET(ident: ::uintptr_t, filter: kevent_filter, flags: kevent_flags, + fflags: kevent_fflags, data: i64, udata: isize) -> kevent { + kevent { + ident: ident, + filter: filter, + flags: flags, + fflags: fflags, + data: data as ::intptr_t, + udata: udata as *mut ::c_void, + } + } } extern { diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 916ed4f29874b..b3158ddc37984 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -5,6 +5,10 @@ pub type blksize_t = ::int32_t; pub type fsblkcnt_t = ::uint64_t; pub type fsfilcnt_t = ::uint64_t; pub type idtype_t = ::c_int; +pub type kevent_nevents = ::size_t; +pub type kevent_filter = ::uint32_t; +pub type kevent_flags = ::uint32_t; +pub type kevent_fflags = ::uint32_t; s! { pub struct aiocb { @@ -649,13 +653,13 @@ pub const PTHREAD_MUTEX_ERRORCHECK: ::c_int = 1; pub const PTHREAD_MUTEX_RECURSIVE: ::c_int = 2; pub const PTHREAD_MUTEX_DEFAULT: ::c_int = PTHREAD_MUTEX_NORMAL; -pub const EVFILT_AIO: ::int32_t = 2; -pub const EVFILT_PROC: ::int32_t = 4; -pub const EVFILT_READ: ::int32_t = 0; -pub const EVFILT_SIGNAL: ::int32_t = 5; -pub const EVFILT_TIMER: ::int32_t = 6; -pub const EVFILT_VNODE: ::int32_t = 3; -pub const EVFILT_WRITE: ::int32_t = 1; +pub const EVFILT_AIO: ::uint32_t = 2; +pub const EVFILT_PROC: ::uint32_t = 4; +pub const EVFILT_READ: ::uint32_t = 0; +pub const EVFILT_SIGNAL: ::uint32_t = 5; +pub const EVFILT_TIMER: ::uint32_t = 6; +pub const EVFILT_VNODE: ::uint32_t = 3; +pub const EVFILT_WRITE: ::uint32_t = 1; pub const EV_ADD: ::uint32_t = 0x1; pub const EV_DELETE: ::uint32_t = 0x2; @@ -885,6 +889,18 @@ f! { pub fn WIFCONTINUED(status: ::c_int) -> bool { status == 0xffff } + + pub fn EV_SET(ident: ::uintptr_t, filter: kevent_filter, flags: kevent_flags, + fflags: kevent_fflags, data: i64, udata: isize) -> kevent { + kevent { + ident: ident, + filter: filter, + flags: flags, + fflags: fflags, + data: data as ::int64_t, + udata: udata as ::intptr_t, + } + } } extern { diff --git a/src/unix/bsd/netbsdlike/openbsdlike/mod.rs b/src/unix/bsd/netbsdlike/openbsdlike/mod.rs index 227e8b3659465..43d342eca7c2d 100644 --- a/src/unix/bsd/netbsdlike/openbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsdlike/mod.rs @@ -14,6 +14,10 @@ pub type pthread_cond_t = *mut ::c_void; pub type pthread_condattr_t = *mut ::c_void; pub type pthread_rwlock_t = *mut ::c_void; pub type pthread_rwlockattr_t = *mut ::c_void; +pub type kevent_nevents = ::c_int; +pub type kevent_filter = ::c_short; +pub type kevent_flags = ::c_ushort; +pub type kevent_fflags = ::c_uint; s! { pub struct dirent { @@ -655,6 +659,18 @@ f! { pub fn WIFCONTINUED(status: ::c_int) -> bool { status & 0o177777 == 0o177777 } + + pub fn EV_SET(ident: ::uintptr_t, filter: kevent_filter, flags: kevent_flags, + fflags: kevent_fflags, data: i64, udata: isize) -> kevent { + kevent { + ident: ident, + filter: filter, + flags: flags, + fflags: fflags, + data: data as ::intptr_t, + udata: udata as *mut ::c_void, + } + } } extern {