pub struct Epoll(pub OwnedFd);
Expand description
A safe wrapper around epoll
.
const DATA: u64 = 17;
const MILLIS: u8 = 100;
// Create epoll
let epoll = Epoll::new(EpollCreateFlags::empty())?;
// Create eventfd & Add event
let eventfd = EventFd::new()?;
epoll.add(&eventfd, EpollEvent::new(EpollFlags::EPOLLIN,DATA))?;
// Arm eventfd & Time wait
eventfd.arm()?;
let now = Instant::now();
// Wait on event
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, MILLIS)?;
// Assert data correct & timeout didn't occur
assert_eq!(events[0].data(), DATA);
assert!(now.elapsed().as_millis() < MILLIS.into());
Tuple Fields§
§0: OwnedFd
Implementations§
source§impl Epoll
impl Epoll
sourcepub fn new(flags: EpollCreateFlags) -> Result<Self>
pub fn new(flags: EpollCreateFlags) -> Result<Self>
Creates a new epoll instance and returns a file descriptor referring to that instance.
sourcepub fn add<Fd: AsFd>(&self, fd: Fd, event: EpollEvent) -> Result<()>
pub fn add<Fd: AsFd>(&self, fd: Fd, event: EpollEvent) -> Result<()>
Add an entry to the interest list of the epoll file descriptor for specified in events.
epoll_ctl
with EPOLL_CTL_ADD
.
sourcepub fn delete<Fd: AsFd>(&self, fd: Fd) -> Result<()>
pub fn delete<Fd: AsFd>(&self, fd: Fd) -> Result<()>
Remove (deregister) the target file descriptor fd
from the interest list.
epoll_ctl
with EPOLL_CTL_DEL
.
sourcepub fn modify<Fd: AsFd>(&self, fd: Fd, event: &mut EpollEvent) -> Result<()>
pub fn modify<Fd: AsFd>(&self, fd: Fd, event: &mut EpollEvent) -> Result<()>
Change the settings associated with fd
in the interest list to the new settings specified
in event
.
epoll_ctl
with EPOLL_CTL_MOD
.
sourcepub fn wait<T: Into<EpollTimeout>>(
&self,
events: &mut [EpollEvent],
timeout: T,
) -> Result<usize>
pub fn wait<T: Into<EpollTimeout>>( &self, events: &mut [EpollEvent], timeout: T, ) -> Result<usize>
Waits for I/O events, blocking the calling thread if no events are currently available. (This can be thought of as fetching items from the ready list of the epoll instance.)
sourcefn epoll_ctl<'a, Fd: AsFd, T>(
&self,
op: EpollOp,
fd: Fd,
event: T,
) -> Result<()>
fn epoll_ctl<'a, Fd: AsFd, T>( &self, op: EpollOp, fd: Fd, event: T, ) -> Result<()>
This system call is used to add, modify, or remove entries in the interest list of the epoll
instance referred to by self
. It requests that the operation op
be performed for the
target file descriptor, fd
.
When possible prefer Epoll::add
, Epoll::delete
and Epoll::modify
.