Struct nix::sys::epoll::Epoll

source ·
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

source

pub fn new(flags: EpollCreateFlags) -> Result<Self>

Creates a new epoll instance and returns a file descriptor referring to that instance.

epoll_create1.

source

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.

source

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 .

source

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.

source

pub fn wait(&self, events: &mut [EpollEvent], timeout: isize) -> 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.)

epoll_wait

Trait Implementations§

source§

impl Debug for Epoll

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.