Skip to content

Commit

Permalink
Add OpenBSD compatibility to events
Browse files Browse the repository at this point in the history
  • Loading branch information
wezm committed Aug 2, 2017
1 parent 607ab97 commit 6870ee6
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ pub struct KEvent {
target_os = "dragonfly", target_os = "macos",
target_os = "ios"))]
type type_of_udata = *mut libc::c_void;
#[cfg(any(target_os = "openbsd", target_os = "freebsd",
target_os = "dragonfly", target_os = "macos",
target_os = "ios"))]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly",
target_os = "macos", target_os = "ios"))]
type type_of_data = libc::intptr_t;
#[cfg(any(target_os = "netbsd"))]
type type_of_udata = intptr_t;
#[cfg(any(target_os = "netbsd"))]
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
type type_of_data = libc::int64_t;

#[cfg(not(target_os = "netbsd"))]
Expand Down Expand Up @@ -79,16 +78,25 @@ pub enum EventFilter {
}

#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "freebsd", target_os = "dragonfly"))]
target_os = "freebsd", target_os = "dragonfly",
target_os = "openbsd"))]
pub type type_of_event_flag = u16;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
#[cfg(any(target_os = "netbsd"))]
pub type type_of_event_flag = u32;
libc_bitflags!{
pub flags EventFlag: type_of_event_flag {
EV_ADD,
EV_CLEAR,
EV_DELETE,
EV_DISABLE,
// No released version of OpenBSD supports EV_DISPATCH or EV_RECEIPT.
// These have been commited to the -current branch though and are
// expected to be part of the OpenBSD 6.2 release in Nov 2017.
// See: https://marc.info/?l=openbsd-tech&m=149621427511219&w=2
// https://github.com/rust-lang/libc/pull/613
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "freebsd", target_os = "dragonfly",
target_os = "netbsd"))]
EV_DISPATCH,
#[cfg(target_os = "freebsd")]
EV_DROP,
Expand All @@ -105,7 +113,9 @@ libc_bitflags!{
EV_OOBAND,
#[cfg(any(target_os = "macos", target_os = "ios"))]
EV_POLL,
#[cfg(not(target_os = "openbsd"))]
#[cfg(any(target_os = "macos", target_os = "ios",
target_os = "freebsd", target_os = "dragonfly",
target_os = "netbsd"))]
EV_RECEIPT,
EV_SYSFLAGS,
}
Expand Down Expand Up @@ -315,13 +325,13 @@ fn test_struct_kevent() {

let expected = libc::kevent{ident: 0xdeadbeef,
filter: libc::EVFILT_READ,
flags: libc::EV_DISPATCH | libc::EV_ADD,
flags: libc::EV_ONESHOT | libc::EV_ADD,
fflags: libc::NOTE_CHILD | libc::NOTE_EXIT,
data: 0x1337,
udata: udata as type_of_udata};
let actual = KEvent::new(0xdeadbeef,
EventFilter::EVFILT_READ,
EV_DISPATCH | EV_ADD,
EV_ONESHOT | EV_ADD,
NOTE_CHILD | NOTE_EXIT,
0x1337,
udata);
Expand Down

0 comments on commit 6870ee6

Please sign in to comment.