Struct base::sys::linux::EventContext

source ·
pub struct EventContext<T> {
    epoll_ctx: File,
    tokens: PhantomData<[T]>,
}
Expand description

Used to poll multiple objects that have file descriptors.

See crate::WaitContext for an example that uses the cross-platform wrapper.

Fields§

§epoll_ctx: File§tokens: PhantomData<[T]>

Implementations§

source§

impl<T: EventToken> EventContext<T>

source

pub fn new() -> Result<EventContext<T>>

Creates a new EventContext.

source

pub fn build_with( fd_tokens: &[(&dyn AsRawDescriptor, T)] ) -> Result<EventContext<T>>

Creates a new EventContext and adds the slice of fd and token tuples to the new context.

This is equivalent to calling new followed by add_many. If there is an error, this will return the error instead of the new context.

source

pub fn add_many(&self, fd_tokens: &[(&dyn AsRawDescriptor, T)]) -> Result<()>

Adds the given slice of fd and token tuples to this context.

This is equivalent to calling add with each fd and token. If there are any errors, this method will stop adding fds and return the first error, leaving this context in a undefined state.

source

pub fn add(&self, fd: &dyn AsRawDescriptor, token: T) -> Result<()>

Adds the given fd to this context and associates the given token with the fd’s readable events.

A fd can only be added once and does not need to be kept open. If the fd is dropped and there were no duplicated file descriptors (i.e. adding the same descriptor with a different FD number) added to this context, events will not be reported by wait anymore.

source

pub fn add_for_event( &self, descriptor: &dyn AsRawDescriptor, event_type: EventType, token: T ) -> Result<()>

Adds the given descriptor to this context, watching for the specified events and associates the given ‘token’ with those events.

A descriptor can only be added once and does not need to be kept open. If the descriptor is dropped and there were no duplicated file descriptors (i.e. adding the same descriptor with a different FD number) added to this context, events will not be reported by wait anymore.

source

pub fn modify( &self, fd: &dyn AsRawDescriptor, event_type: EventType, token: T ) -> Result<()>

If fd was previously added to this context, the watched events will be replaced with event_type and the token associated with it will be replaced with the given token.

source

pub fn delete(&self, fd: &dyn AsRawDescriptor) -> Result<()>

Deletes the given fd from this context. If the fd is not being polled by this context, the call is silently dropped without errors.

If an fd’s token shows up in the list of hangup events, it should be removed using this method or by closing/dropping (if and only if the fd was never dup()’d/fork()’d) the fd. Failure to do so will cause the wait method to always return immediately, causing ~100% CPU load.

source

pub fn wait(&self) -> Result<SmallVec<[TriggeredEvent<T>; 16]>>

Waits for any events to occur in FDs that were previously added to this context.

The events are level-triggered, meaning that if any events are unhandled (i.e. not reading for readable events and not closing for hungup events), subsequent calls to wait will return immediately. The consequence of not handling an event perpetually while calling wait is that the callers loop will degenerated to busy loop polling, pinning a CPU to ~100% usage.

source

pub fn wait_timeout( &self, timeout: Duration ) -> Result<SmallVec<[TriggeredEvent<T>; 16]>>

Like wait except will only block for a maximum of the given timeout.

This may return earlier than timeout with zero events if the duration indicated exceeds system limits.

Trait Implementations§

source§

impl<T: EventToken> AsRawDescriptor for EventContext<T>

source§

fn as_raw_descriptor(&self) -> RawDescriptor

Returns the underlying raw descriptor. Read more

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for EventContext<T>
where T: RefUnwindSafe,

§

impl<T> Send for EventContext<T>
where T: Send,

§

impl<T> Sync for EventContext<T>
where T: Sync,

§

impl<T> Unpin for EventContext<T>
where T: Unpin,

§

impl<T> UnwindSafe for EventContext<T>
where T: UnwindSafe,

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> AsRawDescriptors for T
where T: AsRawDescriptor,

source§

fn as_raw_descriptors(&self) -> Vec<i32>

Returns the underlying raw descriptors. 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.