Skip to main content

Connection

Trait Connection 

Source
pub trait Connection: Send {
    // Required methods
    fn send(&mut self, payload: &[u8]) -> Result<(), TransportError>;
    fn recv(
        &mut self,
        timeout: Option<Duration>,
    ) -> Result<Vec<u8>, TransportError>;
    fn close(&mut self) -> Result<(), TransportError>;

    // Provided methods
    fn supports_sidecars(&self) -> bool { ... }
    fn send_sidecar(&mut self, payload: &[u8]) -> Result<(), TransportError> { ... }
    fn recv_any(
        &mut self,
        timeout: Option<Duration>,
    ) -> Result<Vec<u8>, TransportError> { ... }
}
Expand description

A persistent, bidirectional connection to a remote node.

Required Methods§

Source

fn send(&mut self, payload: &[u8]) -> Result<(), TransportError>

Send a framed payload over the connection.

Source

fn recv(&mut self, timeout: Option<Duration>) -> Result<Vec<u8>, TransportError>

Receive a framed payload. If timeout is None, blocks indefinitely.

Source

fn close(&mut self) -> Result<(), TransportError>

Close the connection gracefully.

Provided Methods§

Source

fn supports_sidecars(&self) -> bool

Whether this connection supports out-of-band sidecar delivery.

When true, sidecars can be sent in parallel on separate streams (e.g. QUIC unidirectional streams). When false, sidecars are sent sequentially on the same connection via send().

Source

fn send_sidecar(&mut self, payload: &[u8]) -> Result<(), TransportError>

Send a sidecar payload. Default: falls back to send().

Source

fn recv_any( &mut self, timeout: Option<Duration>, ) -> Result<Vec<u8>, TransportError>

Receive any incoming message (regular or sidecar). Default: falls back to recv().

Implementors§