Skip to content

Commit

Permalink
Use epoll_create() instead of epoll_create1()
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Jul 2, 2022
1 parent add75b1 commit 40d581a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/sys/unix/selector/epoll.rs
Expand Up @@ -23,21 +23,18 @@ pub struct Selector {

impl Selector {
pub fn new() -> io::Result<Selector> {
// According to libuv, `EPOLL_CLOEXEC` is not defined on Android API <
// 21. But `EPOLL_CLOEXEC` is an alias for `O_CLOEXEC` on that platform,
// so we use it instead.
#[cfg(target_os = "android")]
let flag = libc::O_CLOEXEC;
#[cfg(not(target_os = "android"))]
let flag = libc::EPOLL_CLOEXEC;

syscall!(epoll_create1(flag)).map(|ep| Selector {
#[cfg(debug_assertions)]
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
ep,
#[cfg(debug_assertions)]
has_waker: AtomicBool::new(false),
})
// Using epoll_create() followed by fcntl() instead of epoll_create1() with EPOLL_CLOEXEC
// flag for backwards compatibility. Android API < 21 does not have EPOLL_CLOEXEC constant
// defined and Android API 16 does not have epoll_create1() at all.
syscall!(epoll_create(1))
.and_then(|ep| syscall!(fcntl(ep, libc::F_SETFD, libc::FD_CLOEXEC)).map(|_| ep))
.map(|ep| Selector {
#[cfg(debug_assertions)]
id: NEXT_ID.fetch_add(1, Ordering::Relaxed),
ep,
#[cfg(debug_assertions)]
has_waker: AtomicBool::new(false),
})
}

pub fn try_clone(&self) -> io::Result<Selector> {
Expand Down

0 comments on commit 40d581a

Please sign in to comment.