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
impl Epoll
Sourcepub fn add(&self, fd: RawFd, token: u64) -> Result<()>
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.
Sourcepub fn remove(&self, fd: RawFd) -> Result<()>
pub fn remove(&self, fd: RawFd) -> Result<()>
Unregister an fd from the epoll instance (EPOLL_CTL_DEL).
Sourcepub fn wait_tokens(&self, timeout_ms: i32, out: &mut Vec<u64>) -> Result<()>
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.
Sourcepub fn new(udp_fd: RawFd, tun_fd: RawFd) -> Result<Self>
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).
Sourcepub fn wait(&self, timeout_ms: i32) -> Result<Ready>
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.