[−][src]Struct sys_util::PollContext
Used to poll multiple objects that have file descriptors.
Example
let evt1 = EventFd::new()?; let evt2 = EventFd::new()?; evt2.write(1)?; let ctx: PollContext<u32> = PollContext::new()?; ctx.add(&evt1, 1)?; ctx.add(&evt2, 2)?; let pollevents: PollEvents<u32> = ctx.wait()?; let tokens: Vec<u32> = pollevents.iter_readable().map(|e| e.token()).collect(); assert_eq!(&tokens[..], &[2]);
Methods
impl<T: PollToken> PollContext<T>
[src]
pub fn new() -> Result<PollContext<T>>
[src]
Creates a new PollContext
.
pub fn add(&self, fd: &dyn AsRawFd, token: T) -> Result<()>
[src]
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.
pub fn add_fd_with_events(
&self,
fd: &dyn AsRawFd,
events: WatchingEvents,
token: T
) -> Result<()>
[src]
&self,
fd: &dyn AsRawFd,
events: WatchingEvents,
token: T
) -> Result<()>
Adds the given fd
to this context, watching for the specified events and associates the
given 'token' with those 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.
pub fn modify(
&self,
fd: &dyn AsRawFd,
events: WatchingEvents,
token: T
) -> Result<()>
[src]
&self,
fd: &dyn AsRawFd,
events: WatchingEvents,
token: T
) -> Result<()>
If fd
was previously added to this context, the watched events will be replaced with
events
and the token associated with it will be replaced with the given token
.
pub fn delete(&self, fd: &dyn AsRawFd) -> Result<()>
[src]
Deletes the given fd
from this context.
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.
pub fn wait(&self) -> Result<PollEvents<T>>
[src]
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.
Panics
Panics if the returned PollEvents
structure is not dropped before subsequent wait
calls.
pub fn wait_timeout(&self, timeout: Duration) -> Result<PollEvents<T>>
[src]
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
impl<T: PollToken> IntoRawFd for PollContext<T>
[src]
fn into_raw_fd(self) -> RawFd
[src]
impl<T: PollToken> AsRawFd for PollContext<T>
[src]
Auto Trait Implementations
impl<T> Send for PollContext<T> where
T: Send,
T: Send,
impl<T> !Sync for PollContext<T>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,