Skip to main content

Io

Struct Io 

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

Interface object to the underlying I/O stream

Implementations§

Source§

impl Io

Source

pub fn new<I: IoStream, T: Into<SharedCfg>>(io: I, cfg: T) -> Self

Creates a new Io instance.

Source§

impl<F> Io<F>

Source

pub fn get_ref(&self) -> IoRef

Get an instance of IoRef.

Source

pub fn take(&self) -> Self

Takes the current I/O object.

After this call, the I/O object is no longer valid for use.

Source

pub fn set_config<T: Into<SharedCfg>>(&self, cfg: T)

Updates the shared I/O configuration.

Source§

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

Source

pub fn filter(&self) -> &F

Returns a reference to a filter.

Source§

impl<F: Filter> Io<F>

Source

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

Convert the current I/O stream into a sealed version.

Source

pub fn boxed(self) -> IoBoxed

Convert the current I/O stream into a boxed version.

Source

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

Adds a new processing layer to the current filter chain.

Source

pub fn map_filter<U, R>(self, f: U) -> Io<R>
where U: FnOnce(F) -> R, R: Filter,

Wraps the current layer with a wrapper.

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,

Reads from the incoming I/O stream and decodes a codec item.

Source

pub async fn read(&self, dst: &mut [u8]) -> Result<()>

Reads bytes from this I/O stream into the specified buffer.

If there is not enough data available, waits for incoming data.

Source

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

Waits until the I/O stream is ready for reading.

Source

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

Waits until the I/O stream receives new data.

Source

pub fn pause(&self)

Pauses the read task.

Source

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

Encodes an item and sends it to the peer, fully flushing the write buffer.

Source

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

Wakes the write task and requests a flush of buffered data.

This is the async version of .poll_flush() method.

Source

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

Gracefully shuts down the I/O stream.

Source

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

Polls for read readiness.

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

§Returns

The function returns:

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

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

Polls the I/O stream for availability of 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_recv_decode<U>( &self, codec: &U, cx: &mut Context<'_>, ) -> Result<Decoded<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<()>>

Wakes the write task and instructs it to flush data.

If full is true, wakes the dispatcher when all data has been flushed; otherwise, it wakes when the write buffer size falls below the low-watermark size.

Source

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

Gracefully shuts down the I/O stream.

Source

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

Pauses the read task.

Returns status updates.

Source

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

Polls for available status updates.

Source

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

Registers a dispatch task.

Methods from Deref<Target = IoRef>§

Source

pub fn id(&self) -> Id

Gets the ID.

Source

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

Gets the I/O tag.

Source

pub fn cfg(&self) -> &IoConfig

Gets the configuration.

Source

pub fn shared(&self) -> SharedCfg

Gets the shared configuration.

Source

pub fn is_closed(&self) -> bool

Checks whether the I/O stream is closed.

Source

pub fn is_wr_backpressure(&self) -> bool

Checks whether write back-pressure is enabled.

Source

pub fn close(&self)

Gracefully closes the connection.

Initiates the I/O stream shutdown process.

Source

pub fn terminate(&self)

Force-closes the connection.

The dispatcher does not wait for incomplete responses. The I/O stream is terminated without any graceful period.

Source

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

Queries filter-specific data.

Source

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

Encodes the item into the write buffer.

Source

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

Encodes the slice into the write buffer.

Source

pub fn encode_bytes<B>(&self, src: B) -> Result<()>
where BytePage: From<B>,

Writes bytes to the write buffer.

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 send_buf(&self) -> Result<()>

Sends the write buffer to the I/O layer.

Requires the underlying runtime to implement .write(); otherwise, no action is taken.

Source

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

Get access to filter buffer

Source

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

Get mut access to read buffer

Source

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

Get mut access to source write buffer

Source

pub fn resize_read_buf(&self, buf: &mut BytesMut)

Make sure buffer has enough free space

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

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<I: IoStream> From<I> for Io

Source§

fn from(io: I) -> Io

Converts to this type from the input type.
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<IoBoxed> for Io<Sealed>

Source§

fn from(value: IoBoxed) -> 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 (const: unstable) · 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> UnsafeUnpin for Io<F>

§

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.