Struct mio::io_source::IoSource

source ·
pub struct IoSource<T> {
    state: IoSourceState,
    inner: T,
    selector_id: SelectorId,
}
Expand description

Adapter for a RawFd or RawSocket providing an event::Source implementation.

IoSource enables registering any FD or socket wrapper with Poll.

While only implementations for TCP, UDP, and UDS (Unix only) are provided, Mio supports registering any FD or socket that can be registered with the underlying OS selector. IoSource provides the necessary bridge.

Notes

To handle the registrations and events properly all I/O operations (such as read, write, etc.) must go through the do_io method to ensure the internal state is updated accordingly.

Fields§

§state: IoSourceState§inner: T§selector_id: SelectorId

Implementations§

source§

impl<T> IoSource<T>

source

pub fn new(io: T) -> IoSource<T>

Create a new IoSource.

source

pub fn do_io<F, R>(&self, f: F) -> Result<R>where F: FnOnce(&T) -> Result<R>,

Execute an I/O operations ensuring that the socket receives more events if it hits a WouldBlock error.

Notes

This method is required to be called for all I/O operations to ensure the user will receive events once the socket is ready again after returning a WouldBlock error.

source

pub fn into_inner(self) -> T

Returns the I/O source, dropping the state.

Notes

To ensure no more events are to be received for this I/O source first deregister it.

Trait Implementations§

source§

impl<T> Debug for IoSource<T>where T: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Deref for IoSource<T>

Be careful when using this method. All I/O operations that may block must go through the do_io method.

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T> DerefMut for IoSource<T>

Be careful when using this method. All I/O operations that may block must go through the do_io method.

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T> Source for IoSource<T>where T: AsRawFd,

source§

fn register( &mut self, registry: &Registry, token: Token, interests: Interest ) -> Result<()>

Register self with the given Registry instance. Read more
source§

fn reregister( &mut self, registry: &Registry, token: Token, interests: Interest ) -> Result<()>

Re-register self with the given Registry instance. Read more
source§

fn deregister(&mut self, registry: &Registry) -> Result<()>

Deregister self from the given Registry instance. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.