Skip to main content

Epoll

Struct Epoll 

Source
pub struct Epoll { /* private fields */ }
Expand description

An epoll instance watching a UDP socket fd and a TUN/TAP fd for EPOLLIN.

Owns the epoll fd and closes it on drop. The two watched fds are not owned (they belong to the caller’s UdpSocket/TunTap) and are only referenced to identify readiness in Epoll::wait.

Implementations§

Source§

impl Epoll

Source

pub fn create() -> Result<Self>

Create a new, empty epoll instance with EPOLL_CLOEXEC.

Source

pub fn add(&self, fd: RawFd, token: u64) -> Result<()>

Register one fd for EPOLLIN with the given token user-data.

Sets fd to non-blocking mode as a side effect.

Source

pub fn remove(&self, fd: RawFd) -> Result<()>

Unregister an fd from the epoll instance (EPOLL_CTL_DEL).

Source

pub fn wait_tokens(&self, timeout_ms: i32, out: &mut Vec<u64>) -> Result<()>

Block until at least one registered fd is readable, or timeout_ms milliseconds elapse (-1 blocks indefinitely).

Clears out and appends all ready tokens. On timeout or EINTR, out is left empty and Ok(()) is returned.

Source

pub fn new(udp_fd: RawFd, tun_fd: RawFd) -> Result<Self>

Create an epoll instance registered for EPOLLIN on both udp_fd and tun_fd. Both fds are set non-blocking as a side effect (the driver drains them edge-safely with MSG_DONTWAIT/non-blocking reads).

Source

pub fn wait(&self, timeout_ms: i32) -> Result<Ready>

Block until one of the watched fds is readable, or timeout_ms milliseconds elapse (-1 blocks indefinitely). Returns which fds are ready; an EINTR is reported as “nothing ready” so the caller retries its loop (running its timers) rather than erroring out.

Trait Implementations§

Source§

impl Drop for Epoll

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Epoll

§

impl RefUnwindSafe for Epoll

§

impl Send for Epoll

§

impl Sync for Epoll

§

impl Unpin for Epoll

§

impl UnsafeUnpin for Epoll

§

impl UnwindSafe for Epoll

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.