summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/eventfd.rs32
-rw-r--r--src/sys/mod.rs6
2 files changed, 16 insertions, 22 deletions
diff --git a/src/sys/eventfd.rs b/src/sys/eventfd.rs
index 866c95a3..e8e2bd23 100644
--- a/src/sys/eventfd.rs
+++ b/src/sys/eventfd.rs
@@ -1,37 +1,31 @@
-use std::mem;
-use libc::{c_int, c_uint};
-use errno::Errno;
+use libc;
use fcntl::Fd;
use {Error, Result};
bitflags!(
- flags EventFdFlag: c_int {
+ flags EventFdFlag: libc::c_int {
const EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27
const EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27
const EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30
}
);
-pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
- type F = unsafe extern "C" fn(initval: c_uint, flags: c_int) -> c_int;
+mod ffi {
+ use libc;
extern {
- // #[linkage = "extern_weak"]
- static eventfd: *const ();
+ pub fn eventfd(initval: libc::c_uint, flags: libc::c_int) -> libc::c_int;
}
+}
- if eventfd.is_null() {
- panic!("eventfd unsupported on this platform");
- }
+pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<Fd> {
+ unsafe {
+ let res = ffi::eventfd(initval as libc::c_uint, flags.bits());
- let res = unsafe {
- mem::transmute::<*const (), F>(eventfd)(
- initval as c_uint, flags.bits())
- };
+ if res < 0 {
+ return Err(Error::last());
+ }
- if res < 0 {
- return Err(Error::Sys(Errno::last()));
+ Ok(res as Fd)
}
-
- Ok(res)
}
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index fbd75d23..f25aecb4 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -5,9 +5,9 @@ pub mod epoll;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod event;
-// Dont' support eventfd for now
-// #[cfg(any(target_os = "linux", target_os = "android"))]
-// pub mod eventfd;
+// TODO: switch from feature flags to conditional builds
+#[cfg(feature = "eventfd")]
+pub mod eventfd;
#[cfg(not(target_os = "ios"))]
pub mod ioctl;