Trait libp2p::core::muxing::StreamMuxer

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§

type Substream: AsyncRead + AsyncWrite

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

type Error: Error

Error type of the muxer

Required Methods§

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.

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

Poll for a new, outbound substream.

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.

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.

Implementations on Foreign Types§

§

impl StreamMuxer for Connection

§

type Substream = Stream

§

type Error = Error

§

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

§

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

§

fn poll( self: Pin<&mut Connection>, _cx: &mut Context<'_> ) -> Poll<Result<StreamMuxerEvent, <Connection as StreamMuxer>::Error>>

§

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

§

impl<A, B> StreamMuxer for Either<A, B>
where A: StreamMuxer, B: StreamMuxer,

§

type Substream = Either<<A as StreamMuxer>::Substream, <B as StreamMuxer>::Substream>

§

type Error = Either<<A as StreamMuxer>::Error, <B as StreamMuxer>::Error>

§

fn poll_inbound( self: Pin<&mut Either<A, B>>, cx: &mut Context<'_> ) -> Poll<Result<<Either<A, B> as StreamMuxer>::Substream, <Either<A, B> as StreamMuxer>::Error>>

§

fn poll_outbound( self: Pin<&mut Either<A, B>>, cx: &mut Context<'_> ) -> Poll<Result<<Either<A, B> as StreamMuxer>::Substream, <Either<A, B> as StreamMuxer>::Error>>

§

fn poll_close( self: Pin<&mut Either<A, B>>, cx: &mut Context<'_> ) -> Poll<Result<(), <Either<A, B> as StreamMuxer>::Error>>

§

fn poll( self: Pin<&mut Either<A, B>>, cx: &mut Context<'_> ) -> Poll<Result<StreamMuxerEvent, <Either<A, B> as StreamMuxer>::Error>>

Implementors§

§

impl StreamMuxer for libp2p::webtransport_websys::Connection

WebTransport native multiplexing

§

impl StreamMuxer for StreamMuxerBox

§

impl<C> StreamMuxer for Muxer<C>
where C: AsyncRead + AsyncWrite + Unpin + 'static,