mod direction;
#[cfg(miri)]
mod dummy;
#[cfg(all(any(target_os = "linux", target_os = "android"), not(miri)))]
mod epoll;
mod io_change;
mod kernel_timer;
#[cfg(all(target_os = "macos", not(miri)))]
mod kqueue;
mod selector_event;
mod timer_change;
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "android")))]
compile_error!("externally-driven-async-rt supports only macOS, Linux and Android");
use rustix::fd::{AsFd, BorrowedFd};
#[cfg(miri)]
use self::dummy::DummySelector as Backend;
#[cfg(all(any(target_os = "linux", target_os = "android"), not(miri)))]
use self::epoll::EpollSelector as Backend;
#[cfg(all(target_os = "macos", not(miri)))]
use self::kqueue::KqueueSelector as Backend;
pub(crate) use self::{
direction::{Direction, Directions},
io_change::IoChange,
kernel_timer::KernelTimer,
selector_event::{EVENTS_PER_CALL, SelectorEvent},
timer_change::TimerChange,
};
use crate::time::Instant;
#[must_use]
pub struct Selector {
backend: Backend,
}
impl Selector {
pub fn new() -> rustix::io::Result<Self> {
Ok(Self {
backend: Backend::new()?,
})
}
pub(crate) fn apply_now(&self, change: IoChange) -> rustix::io::Result<()> {
self.backend.apply_now(change)
}
pub(crate) fn notify(&self) -> rustix::io::Result<()> {
self.backend.notify()
}
pub(crate) fn flush(
&self,
io_changes: impl IntoIterator<Item = IoChange>,
deadline: Option<Instant>,
now: Instant,
) -> rustix::io::Result<()> {
self.backend.flush(io_changes, deadline, now)
}
pub(crate) fn poll_nonblocking(
&self,
out: &mut [Option<SelectorEvent>; EVENTS_PER_CALL],
) -> rustix::io::Result<bool> {
self.backend.poll_nonblocking(out)
}
pub(crate) fn as_fd(&self) -> BorrowedFd<'_> {
self.backend.as_fd()
}
}