Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eventfd: Follow nix conventions #383

Merged
merged 1 commit into from
Jul 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/sys/eventfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ use libc;
use std::os::unix::io::RawFd;
use {Errno, Result};

bitflags!(
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
}
);

mod ffi {
use libc;

extern {
pub fn eventfd(initval: libc::c_uint, flags: libc::c_int) -> libc::c_int;
libc_bitflags! {
flags EfdFlags: libc::c_int {
const EFD_CLOEXEC, // Since Linux 2.6.27
const EFD_NONBLOCK, // Since Linux 2.6.27
const EFD_SEMAPHORE, // Since Linux 2.6.30
}
}

pub fn eventfd(initval: usize, flags: EventFdFlag) -> Result<RawFd> {
unsafe {
let res = ffi::eventfd(initval as libc::c_uint, flags.bits());
pub fn eventfd(initval: libc::c_uint, flags: EfdFlags) -> Result<RawFd> {
let res = unsafe { libc::eventfd(initval, flags.bits()) };

Errno::result(res).map(|r| r as RawFd)
}
Errno::result(res).map(|r| r as RawFd)
}