Skip to main content

Transport

Trait Transport 

Source
pub trait Transport<A: Address>:
    Send
    + Sync
    + Unpin
    + 'static {
    type Io: AsyncRead + AsyncWrite + PeerAddress<A> + Send + Unpin;
    type Stats: Default + Debug + Send + Sync + for<'a> TryFrom<&'a Self::Io, Error: Debug>;
    type Error: Error + From<Error> + Send + Sync;
    type Connect: Future<Output = Result<Self::Io, Self::Error>> + Send;
    type Accept: Future<Output = Result<Self::Io, Self::Error>> + Send + Unpin;
    type Control: Send + Sync + Unpin;

    // Required methods
    fn local_addr(&self) -> Option<A>;
    fn bind<'life0, 'async_trait>(
        &'life0 mut self,
        addr: A,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn connect(&mut self, addr: A) -> Self::Connect;
    fn poll_accept(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Self::Accept>;

    // Provided method
    fn on_control(&mut self, _ctrl: Self::Control) { ... }
}
Expand description

A transport provides connection-oriented communication between two peers through ordered and reliable streams of bytes.

It provides an interface to manage both inbound and outbound connections.

Required Associated Types§

Source

type Io: AsyncRead + AsyncWrite + PeerAddress<A> + Send + Unpin

The result of a successful connection.

The output type is transport-specific, and can be a handle to directly write to the connection, or it can be a substream multiplexer in the case of stream protocols.

Source

type Stats: Default + Debug + Send + Sync + for<'a> TryFrom<&'a Self::Io, Error: Debug>

The statistics for the transport (specifically its underlying IO object).

Source

type Error: Error + From<Error> + Send + Sync

An error that occurred when setting up the connection.

Source

type Connect: Future<Output = Result<Self::Io, Self::Error>> + Send

A pending output for an outbound connection, obtained when calling Transport::connect.

Source

type Accept: Future<Output = Result<Self::Io, Self::Error>> + Send + Unpin

A pending output for an inbound connection, obtained when calling Transport::poll_accept.

Source

type Control: Send + Sync + Unpin

Control-plane messages that modify the runtime behavior of the transport.

Required Methods§

Source

fn local_addr(&self) -> Option<A>

Returns the local address this transport is bound to (if it is bound).

Source

fn bind<'life0, 'async_trait>( &'life0 mut self, addr: A, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Binds to the given address.

Source

fn connect(&mut self, addr: A) -> Self::Connect

Connects to the given address, returning a future representing a pending outbound connection.

Source

fn poll_accept(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Accept>

Poll for incoming connections. If an inbound connection is received, a future representing a pending inbound connection is returned. The future will resolve to Transport::Accept.

Provided Methods§

Source

fn on_control(&mut self, _ctrl: Self::Control)

Applies a control-plane message to the transport. It is expected to update internal state only and should not perform long-running operations.

Implementors§