summaryrefslogtreecommitdiff
path: root/src/sys/eventfd.rs
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2014-09-21 23:47:04 -0700
committerCarl Lerche <me@carllerche.com>2014-09-21 23:47:04 -0700
commita4ce09b497cee146a6dd2cc8ff115ae1a43c838a (patch)
tree2b7b8dc846d159331a650ce8a65e17ffe1577c6e /src/sys/eventfd.rs
parentc013030a512af7c8c2dd2251cd7a18160a80f11e (diff)
downloadnix-a4ce09b497cee146a6dd2cc8ff115ae1a43c838a.zip
Bind eventfd()
Diffstat (limited to 'src/sys/eventfd.rs')
-rw-r--r--src/sys/eventfd.rs29
1 files changed, 29 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)
+}