Skip to content

Commit

Permalink
Provide EV_SET along with a number of helper types for kqueue/kevent
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechkral committed Oct 8, 2017
1 parent e4f8ab8 commit db1b27d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
4 changes: 4 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {
Expand Down
30 changes: 23 additions & 7 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions src/unix/bsd/netbsdlike/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit db1b27d

Please sign in to comment.