summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2014-08-21 17:48:45 -0700
committerCarl Lerche <me@carllerche.com>2014-08-21 17:48:45 -0700
commitf4b9966038514458c65028a2569f9bb69e67aac7 (patch)
treef7be5158de832df37eee9b5edf1a8762ce78a715
parent2abaad5fbce61ec566a244c1d2eae2bc3aa5fd5b (diff)
downloadnix-f4b9966038514458c65028a2569f9bb69e67aac7.zip
Fix O_* flags for Darwin. Minor kqueue tweaks.
-rw-r--r--src/fcntl.rs38
-rw-r--r--src/sys/event.rs58
2 files changed, 64 insertions, 32 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index 80290aec..9f3c28db 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -157,27 +157,23 @@ mod consts {
bitflags!(
flags OFlag: c_int {
- static O_ACCMODE = 0o00000003,
- static O_RDONLY = 0o00000000,
- static O_WRONLY = 0o00000001,
- static O_RDWR = 0o00000002,
- static O_CREAT = 0o00000100,
- static O_EXCL = 0o00000200,
- static O_NOCTTY = 0o00000400,
- static O_TRUNC = 0o00001000,
- static O_APPEND = 0o00002000,
- static O_NONBLOCK = 0o00004000,
- static O_DSYNC = 0o00010000,
- static O_DIRECT = 0o00040000,
- static O_LARGEFILE = 0o00100000,
- static O_DIRECTORY = 0o00200000,
- static O_NOFOLLOW = 0o00400000,
- static O_NOATIME = 0o01000000,
- static O_CLOEXEC = 0o02000000,
- static O_SYNC = 0o04000000,
- static O_PATH = 0o10000000,
- static O_TMPFILE = 0o20000000,
- static O_NDELAY = O_NONBLOCK.bits
+ static O_ACCMODE = 0x0000003,
+ static O_RDONLY = 0x0000000,
+ static O_WRONLY = 0x0000001,
+ static O_RDWR = 0x0000002,
+ static O_CREAT = 0x0000200,
+ static O_EXCL = 0x0000800,
+ static O_NOCTTY = 0x0020000,
+ static O_TRUNC = 0x0000400,
+ static O_APPEND = 0x0000008,
+ static O_NONBLOCK = 0x0000004,
+ static O_DSYNC = 0x0400000,
+ static O_DIRECTORY = 0x0100000,
+ static O_NOFOLLOW = 0x0000100,
+ static O_CLOEXEC = 0x1000000,
+ static O_SYNC = 0x0000080,
+ static O_NDELAY = O_NONBLOCK.bits,
+ static O_FSYNC = O_SYNC.bits
}
)
diff --git a/src/sys/event.rs b/src/sys/event.rs
index 335f9ad8..4f562201 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -1,20 +1,21 @@
-use libc::{timespec, time_t, c_int, c_long};
+use libc::{timespec, time_t, c_int, c_long, c_void};
use errno::{SysResult, SysError};
use fcntl::Fd;
pub use self::ffi::kevent as KEvent;
mod ffi {
- pub use libc::{c_int, c_void, timespec};
+ pub use libc::{c_int, c_void, uintptr_t, intptr_t, timespec};
+ use super::{EventFilter, EventFlag, FilterFlag};
// Packed to 32 bytes
pub struct kevent {
- pub ident: uint, // 8
- pub filter: i16, // 2
- pub flags: u16, // 2
- pub fflags: u32, // 4
- pub data: int, // 8
- pub udata: *mut c_void // 8
+ pub ident: uintptr_t, // 8
+ pub filter: EventFilter, // 2
+ pub flags: EventFlag, // 2
+ pub fflags: FilterFlag, // 4
+ pub data: intptr_t, // 8
+ pub udata: *mut c_void // 8
}
extern {
@@ -30,7 +31,8 @@ mod ffi {
}
}
-#[repr(C)]
+#[repr(i16)]
+#[deriving(Show, PartialEq)]
pub enum EventFilter {
EVFILT_READ = -1,
EVFILT_WRITE = -2,
@@ -115,8 +117,14 @@ bitflags!(
pub static EV_POLL: EventFlag = EV_FLAG0;
pub static EV_OOBAND: EventFlag = EV_FLAG1;
-pub fn kqueue() -> Fd {
- unsafe { ffi::kqueue() }
+pub fn kqueue() -> SysResult<Fd> {
+ let res = unsafe { ffi::kqueue() };
+
+ if res < 0 {
+ return Err(SysError::last());
+ }
+
+ Ok(res)
}
pub fn kevent(kq: Fd,
@@ -146,3 +154,31 @@ pub fn kevent(kq: Fd,
return Ok(res as uint)
}
+
+/*
+ // Packed to 32 bytes
+ pub struct kevent {
+ pub ident: uintptr_t, // 8
+ pub filter: i16, // 2
+ pub flags: u16, // 2
+ pub fflags: u32, // 4
+ pub data: intptr_t, // 8
+ pub udata: *mut c_void // 8
+ }
+ */
+
+#[inline]
+pub fn ev_set(ev: &mut KEvent,
+ ident: uint,
+ filter: EventFilter,
+ flags: EventFlag,
+ fflags: FilterFlag,
+ udata: *mut c_void) {
+
+ ev.ident = ident;
+ ev.filter = filter;
+ ev.flags = flags;
+ ev.fflags = fflags;
+ ev.data = 0;
+ ev.udata = udata;
+}