pub struct Epoll(pub OwnedFd);
Expand description
A safe wrapper around epoll
.
const DATA: u64 = 17;
const MILLIS: u64 = 100;
// Create epoll
let epoll = Epoll::new(EpollCreateFlags::empty())?;
// Create eventfd & Add event
let eventfd = eventfd(0, EfdFlags::empty())?;
epoll.add(&eventfd, EpollEvent::new(EpollFlags::EPOLLIN,DATA))?;
// Arm eventfd & Time wait
write(eventfd.as_raw_fd(), &1u64.to_ne_bytes())?;
let now = Instant::now();
// Wait on event
let mut events = [EpollEvent::empty()];
epoll.wait(&mut events, MILLIS as isize)?;
// Assert data correct & timeout didn't occur
assert_eq!(events[0].data(), DATA);
assert!(now.elapsed() < Duration::from_millis(MILLIS));
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
.
Trait Implementations§
Auto Trait Implementations§
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