mirror of https://github.com/stjepang/smol
refactor: use libc for eventfd
This commit is contained in:
parent
b500e5ce2b
commit
f647532400
|
@ -114,7 +114,7 @@ fn notifier() -> io::Result<(Socket, Socket)> {
|
|||
#[cfg(target_os = "linux")]
|
||||
mod linux {
|
||||
use super::*;
|
||||
use crate::sys::eventfd::{eventfd, EfdFlags};
|
||||
use crate::sys::eventfd::eventfd;
|
||||
use crate::sys::unistd;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
|
@ -122,7 +122,7 @@ mod linux {
|
|||
|
||||
impl EventFd {
|
||||
pub fn new() -> Result<Self, std::io::Error> {
|
||||
let fd = eventfd(0, EfdFlags::EFD_CLOEXEC | EfdFlags::EFD_NONBLOCK).map_err(io_err)?;
|
||||
let fd = eventfd(0, libc::EFD_CLOEXEC | libc::EFD_NONBLOCK)?;
|
||||
Ok(EventFd(fd))
|
||||
}
|
||||
|
||||
|
@ -143,13 +143,6 @@ mod linux {
|
|||
}
|
||||
}
|
||||
|
||||
fn io_err(err: crate::sys::Error) -> io::Error {
|
||||
match err {
|
||||
crate::sys::Error::Sys(code) => code.into(),
|
||||
err => io::Error::new(io::ErrorKind::Other, Box::new(err)),
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for &EventFd {
|
||||
#[inline]
|
||||
fn read(&mut self, buf: &mut [u8]) -> std::result::Result<usize, std::io::Error> {
|
||||
|
|
11
src/sys.rs
11
src/sys.rs
|
@ -1,6 +1,15 @@
|
|||
#[cfg(target_os = "linux")]
|
||||
pub mod eventfd {
|
||||
pub use nix::sys::eventfd::{eventfd, EfdFlags};
|
||||
use super::check_err;
|
||||
use std::os::unix::io::RawFd;
|
||||
|
||||
pub type EfdFlags = libc::c_int;
|
||||
|
||||
pub fn eventfd(initval: libc::c_uint, flags: EfdFlags) -> Result<RawFd, std::io::Error> {
|
||||
let res = unsafe { libc::eventfd(initval, flags) };
|
||||
|
||||
check_err(res).map(|r| r as RawFd)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
Loading…
Reference in New Issue