mio::event

Struct Event

Source
pub struct Event { /* private fields */ }
Expand description

A readiness event.

Event is a readiness state paired with a Token. It is returned by Poll::poll.

For more documentation on polling and events, see Poll.

Implementations§

Source§

impl Event

Source

pub fn token(&self) -> Token

Returns the event’s token.

Source

pub fn is_readable(&self) -> bool

Returns true if the event contains readable readiness.

§Notes

Out-of-band (OOB) data also triggers readable events. But most applications don’t actually read OOB data, this could leave an application open to a Denial-of-Service (Dos) attack, see https://github.com/sandstorm-io/sandstorm-website/blob/58f93346028c0576e8147627667328eaaf4be9fa/_posts/2015-04-08-osx-security-bug.md. However because Mio uses edge-triggers it will not result in an infinite loop as described in the article above.

Source

pub fn is_writable(&self) -> bool

Returns true if the event contains writable readiness.

Source

pub fn is_error(&self) -> bool

Returns true if the event contains error readiness.

Error events occur when the socket enters an error state. In this case, the socket will also receive a readable or writable event. Reading or writing to the socket will result in an error.

§Notes

Method is available on all platforms, but not all platforms trigger the error event.

The table below shows what flags are checked on what OS.

OS selectorFlag(s) checked
epollEPOLLERR
kqueueEV_ERROR and EV_EOF with fflags set to 0.
Source

pub fn is_read_closed(&self) -> bool

Returns true if the event contains read closed readiness.

§Notes

Read closed readiness can be expected after any of the following have occurred:

  • The local stream has shutdown the read half of its socket
  • The local stream has shutdown both the read half and the write half of its socket
  • The peer stream has shutdown the write half its socket; this sends a FIN packet that has been received by the local stream

Method is a best effort implementation. While some platforms may not return readiness when read half is closed, it is guaranteed that false-positives will not occur.

The table below shows what flags are checked on what OS.

OS selectorFlag(s) checked
epollEPOLLHUP, or
EPOLLIN and EPOLLRDHUP
kqueueEV_EOF
Source

pub fn is_write_closed(&self) -> bool

Returns true if the event contains write closed readiness.

§Notes

On epoll this is essentially a check for EPOLLHUP flag as the local stream shutting down its write half does not trigger this event.

On kqueue the local stream shutting down the write half of its socket will trigger this event.

Method is a best effort implementation. While some platforms may not return readiness when write half is closed, it is guaranteed that false-positives will not occur.

The table below shows what flags are checked on what OS.

OS selectorFlag(s) checked
epollEPOLLHUP, or
only EPOLLERR, or
EPOLLOUT and EPOLLERR
kqueueEV_EOF
Source

pub fn is_priority(&self) -> bool

Returns true if the event contains priority readiness.

§Notes

Method is available on all platforms, but not all platforms trigger the priority event.

The table below shows what flags are checked on what OS.

OS selectorFlag(s) checked
epollEPOLLPRI
kqueueNot supported
Source

pub fn is_aio(&self) -> bool

Returns true if the event contains AIO readiness.

§Notes

Method is available on all platforms, but not all platforms support AIO.

The table below shows what flags are checked on what OS.

OS selectorFlag(s) checked
epollNot supported
kqueue1EVFILT_AIO

1: Only supported on DragonFly BSD, FreeBSD, iOS and macOS.

Source

pub fn is_lio(&self) -> bool

Returns true if the event contains LIO readiness.

§Notes

Method is available on all platforms, but only FreeBSD supports LIO. On FreeBSD this method checks the EVFILT_LIO flag.

Trait Implementations§

Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

When the alternate flag is enabled this will print platform specific details, for example the fields of the kevent structure on platforms that use kqueue(2). Note however that the output of this implementation is not consider a part of the stable API.

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Event

§

impl RefUnwindSafe for Event

§

impl Send for Event

§

impl Sync for Event

§

impl Unpin for Event

§

impl UnwindSafe for Event

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 12 bytes