ntex_io

Struct Io

source
pub struct Io<F = Base>(/* private fields */);
Expand description

Interface object to underlying io stream

Implementations§

source§

impl Io

source

pub fn new<I: IoStream>(io: I) -> Self

Create Io instance

source

pub fn with_memory_pool<I: IoStream>(io: I, pool: PoolRef) -> Self

Create Io instance in specific memory pool.

source§

impl<F> Io<F>

source

pub fn set_memory_pool(&self, pool: PoolRef)

Set memory pool

source

pub fn set_disconnect_timeout(&self, timeout: Seconds)

Set io disconnect timeout in millis

source

pub fn take(&self) -> Self

Clone current io object.

Current io object becomes closed.

source§

impl<F> Io<F>

source

pub fn get_ref(&self) -> IoRef

Get instance of IoRef

source§

impl<F: FilterLayer, T: Filter> Io<Layer<F, T>>

source

pub fn filter(&self) -> &F

Get referece to a filter

source§

impl<F: Filter> Io<F>

source

pub fn seal(self) -> Io<Sealed>

Convert current io stream into sealed version

source

pub fn add_filter<U>(self, nf: U) -> Io<Layer<U, F>>
where U: FilterLayer,

Map current filter with new one

source§

impl<F> Io<F>

source

pub async fn recv<U>( &self, codec: &U, ) -> Result<Option<U::Item>, Either<U::Error, Error>>
where U: Decoder,

Read incoming io stream and decode codec item.

source

pub async fn read_ready(&self) -> Result<Option<()>>

Wait until read becomes ready.

source

pub async fn read_notify(&self) -> Result<Option<()>>

Wait until io reads any data.

source

pub fn pause(&self)

Pause read task

source

pub async fn send<U>( &self, item: U::Item, codec: &U, ) -> Result<(), Either<U::Error, Error>>
where U: Encoder,

Encode item, send to the peer. Fully flush write buffer.

source

pub async fn flush(&self, full: bool) -> Result<()>

Wake write task and instruct to flush data.

This is async version of .poll_flush() method.

source

pub async fn shutdown(&self) -> Result<()>

Gracefully shutdown io stream

source

pub fn poll_read_ready(&self, cx: &mut Context<'_>) -> Poll<Result<Option<()>>>

Polls for read readiness.

If the io stream is not currently ready for reading, this method will store a clone of the Waker from the provided Context. When the io stream becomes ready for reading, Waker::wake will be called on the waker.

Return value The function returns:

Poll::Pending if the io stream is not ready for reading. Poll::Ready(Ok(Some(())))) if the io stream is ready for reading. Poll::Ready(Ok(None)) if io stream is disconnected Some(Poll::Ready(Err(e))) if an error is encountered.

source

pub fn poll_read_notify(&self, cx: &mut Context<'_>) -> Poll<Result<Option<()>>>

Polls for any incoming data.

source

pub fn poll_recv<U>( &self, codec: &U, cx: &mut Context<'_>, ) -> Poll<Result<U::Item, RecvError<U>>>
where U: Decoder,

Decode codec item from incoming bytes stream.

Wake read task and request to read more data if data is not enough for decoding. If error get returned this method does not register waker for later wake up action.

source

pub fn poll_flush(&self, cx: &mut Context<'_>, full: bool) -> Poll<Result<()>>

Wake write task and instruct to flush data.

If full is true then wake up dispatcher when all data is flushed otherwise wake up when size of write buffer is lower than buffer max size.

source

pub fn poll_shutdown(&self, cx: &mut Context<'_>) -> Poll<Result<()>>

Gracefully shutdown io stream

source

pub fn poll_read_pause(&self, cx: &mut Context<'_>) -> Poll<IoStatusUpdate>

Pause read task

Returns status updates

source

pub fn poll_status_update(&self, cx: &mut Context<'_>) -> Poll<IoStatusUpdate>

Wait for status updates

source

pub fn poll_dispatch(&self, cx: &mut Context<'_>)

Register dispatch task

Methods from Deref<Target = IoRef>§

source

pub fn memory_pool(&self) -> PoolRef

Get memory pool

source

pub fn is_closed(&self) -> bool

Check if io stream is closed

source

pub fn is_wr_backpressure(&self) -> bool

Check if write back-pressure is enabled

source

pub fn wake(&self)

Wake dispatcher task

source

pub fn close(&self)

Gracefully close connection

Notify dispatcher and initiate io stream shutdown process.

source

pub fn force_close(&self)

Force close connection

Dispatcher does not wait for uncompleted responses. Io stream get terminated without any graceful period.

source

pub fn want_shutdown(&self)

Gracefully shutdown io stream

source

pub fn query<T: 'static>(&self) -> QueryItem<T>

Query filter specific data

source

pub fn encode<U>( &self, item: U::Item, codec: &U, ) -> Result<(), <U as Encoder>::Error>
where U: Encoder,

Encode and write item to a buffer and wake up write task

source

pub fn decode<U>( &self, codec: &U, ) -> Result<Option<<U as Decoder>::Item>, <U as Decoder>::Error>
where U: Decoder,

Attempts to decode a frame from the read buffer

source

pub fn decode_item<U>( &self, codec: &U, ) -> Result<Decoded<<U as Decoder>::Item>, <U as Decoder>::Error>
where U: Decoder,

Attempts to decode a frame from the read buffer

source

pub fn write(&self, src: &[u8]) -> Result<()>

Write bytes to a buffer and wake up write task

source

pub fn with_buf<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&WriteBuf<'_>) -> R,

Get access to write buffer

source

pub fn with_write_buf<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&mut BytesVec) -> R,

Get mut access to source write buffer

source

pub fn with_read_buf<F, R>(&self, f: F) -> R
where F: FnOnce(&mut BytesVec) -> R,

Get mut access to source read buffer

source

pub fn notify_dispatcher(&self)

Wakeup dispatcher

source

pub fn notify_timeout(&self)

Wakeup dispatcher and send keep-alive error

source

pub fn timer_handle(&self) -> TimerHandle

current timer handle

source

pub fn start_timer(&self, timeout: Seconds) -> TimerHandle

Start timer

source

pub fn stop_timer(&self)

Stop timer

source

pub fn tag(&self) -> &'static str

Get tag

source

pub fn set_tag(&self, tag: &'static str)

Set tag

source

pub fn on_disconnect(&self) -> OnDisconnect

Notify when io stream get disconnected

Trait Implementations§

source§

impl<F> AsRef<IoRef> for Io<F>

source§

fn as_ref(&self) -> &IoRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<F> Debug for Io<F>

source§

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

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

impl<F> Deref for Io<F>

source§

type Target = IoRef

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<F> Drop for Io<F>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<F: Filter> From<Io<F>> for IoBoxed

source§

fn from(io: Io<F>) -> Self

Converts to this type from the input type.
source§

impl From<Io<Sealed>> for IoBoxed

source§

fn from(io: Io<Sealed>) -> Self

Converts to this type from the input type.
source§

impl<F> Hash for Io<F>

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<F> PartialEq for Io<F>

source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<F> Eq for Io<F>

Auto Trait Implementations§

§

impl<F = Base> !Freeze for Io<F>

§

impl<F = Base> !RefUnwindSafe for Io<F>

§

impl<F = Base> !Send for Io<F>

§

impl<F = Base> !Sync for Io<F>

§

impl<F> Unpin for Io<F>
where F: Unpin,

§

impl<F = Base> !UnwindSafe for Io<F>

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

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.