pub trait StreamMuxer {
    type Substream: AsyncRead + AsyncWrite;
    type Error: Error;

    // Required methods
    fn poll_inbound(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Self::Substream, Self::Error>>;
    fn poll_outbound(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<Self::Substream, Self::Error>>;
    fn poll_close(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<(), Self::Error>>;
    fn poll(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>
    ) -> Poll<Result<StreamMuxerEvent, Self::Error>>;
}
Expand description

Provides multiplexing for a connection by allowing users to open substreams.

A substream created by a StreamMuxer is a type that implements AsyncRead and AsyncWrite. The StreamMuxer itself is modelled closely after AsyncWrite. It features poll-style functions that allow the implementation to make progress on various tasks.

Required Associated Types§

source

type Substream: AsyncRead + AsyncWrite

Type of the object that represents the raw substream where data can be read and written.

source

type Error: Error

Error type of the muxer

Required Methods§

source

fn poll_inbound( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Self::Substream, Self::Error>>

Poll for new inbound substreams.

This function should be called whenever callers are ready to accept more inbound streams. In other words, callers may exercise back-pressure on incoming streams by not calling this function if a certain limit is hit.

source

fn poll_outbound( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<Self::Substream, Self::Error>>

Poll for a new, outbound substream.

source

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Poll to close this StreamMuxer.

After this has returned Poll::Ready(Ok(())), the muxer has become useless and may be safely dropped.

Note: You are encouraged to call this method and wait for it to return Ready, so that the remote is properly informed of the shutdown. However, apart from properly informing the remote, there is no difference between this and immediately dropping the muxer.

source

fn poll( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<StreamMuxerEvent, Self::Error>>

Poll to allow the underlying connection to make progress.

In contrast to all other poll-functions on StreamMuxer, this function MUST be called unconditionally. Because it will be called regardless, this function can be used by implementations to return events about the underlying connection that the caller MUST deal with.

Implementors§