diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/eventfd.rs | 29 | ||||
-rw-r--r-- | src/sys/mod.rs | 3 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs new file mode 100644 index 00000000..178cd277 --- /dev/null +++ b/src/sys/eventfd.rs @@ -0,0 +1,29 @@ +use libc::{c_int, c_uint}; +use fcntl::Fd; +use errno::{SysResult, SysError, from_ffi}; + +mod ffi { + use libc::{c_int, c_uint}; + + extern { + pub fn eventfd(initval: c_uint, flags: c_int) -> c_int; + } +} + +bitflags!( + flags EventFdFlag: c_int { + static EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27 + static EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27 + static EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30 + } +) + +pub fn eventfd(initval: uint, flags: EventFdFlag) -> SysResult<Fd> { + let res = unsafe { ffi::eventfd(initval as c_uint, flags.bits()) }; + + if res < 0 { + return Err(SysError::last()); + } + + Ok(res) +} diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 9e99458b..6052b2fd 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -7,6 +7,9 @@ pub mod epoll; pub mod event; #[cfg(target_os = "linux")] +pub mod eventfd; + +#[cfg(target_os = "linux")] #[cfg(target_os = "macos")] #[cfg(target_os = "ios")] pub mod socket; |