Skip to content

Commit a4ce09b

Browse files
committed
Bind eventfd()
1 parent c013030 commit a4ce09b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/sys/eventfd.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use libc::{c_int, c_uint};
2+
use fcntl::Fd;
3+
use errno::{SysResult, SysError, from_ffi};
4+
5+
mod ffi {
6+
use libc::{c_int, c_uint};
7+
8+
extern {
9+
pub fn eventfd(initval: c_uint, flags: c_int) -> c_int;
10+
}
11+
}
12+
13+
bitflags!(
14+
flags EventFdFlag: c_int {
15+
static EFD_CLOEXEC = 0o2000000, // Since Linux 2.6.27
16+
static EFD_NONBLOCK = 0o0004000, // Since Linux 2.6.27
17+
static EFD_SEMAPHORE = 0o0000001, // Since Linux 2.6.30
18+
}
19+
)
20+
21+
pub fn eventfd(initval: uint, flags: EventFdFlag) -> SysResult<Fd> {
22+
let res = unsafe { ffi::eventfd(initval as c_uint, flags.bits()) };
23+
24+
if res < 0 {
25+
return Err(SysError::last());
26+
}
27+
28+
Ok(res)
29+
}

src/sys/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ pub mod epoll;
66
#[cfg(target_os = "ios")]
77
pub mod event;
88

9+
#[cfg(target_os = "linux")]
10+
pub mod eventfd;
11+
912
#[cfg(target_os = "linux")]
1013
#[cfg(target_os = "macos")]
1114
#[cfg(target_os = "ios")]

0 commit comments

Comments
 (0)