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.write(1)?;
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.)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Epoll
impl RefUnwindSafe for Epoll
impl Send for Epoll
impl Sync for Epoll
impl Unpin for Epoll
impl UnwindSafe for Epoll
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more