Skip to main content

QuicConnectionTrait

Trait QuicConnectionTrait 

Source
pub trait QuicConnectionTrait:
    Clone
    + Send
    + Sync
    + 'static {
    type BidiStream: QuicTransportBidi + Unpin + Send + Sync + 'static;
    type RecvStream: QuicTransportReceive + Unpin + Send + Sync + 'static;
    type SendStream: QuicTransportSend + Unpin + Send + Sync + 'static;

    // Required methods
    fn accept_bidi(
        &self,
    ) -> impl Future<Output = Result<(u64, Self::BidiStream)>> + Send;
    fn accept_uni(
        &self,
    ) -> impl Future<Output = Result<(u64, Self::RecvStream)>> + Send;
    fn open_uni(
        &self,
    ) -> impl Future<Output = Result<(u64, Self::SendStream)>> + Send;
    fn open_bidi(
        &self,
    ) -> impl Future<Output = Result<(u64, Self::BidiStream)>> + Send;
    fn remote_address(&self) -> SocketAddr;
    fn close(&self, error_code: u64, reason: &[u8]);
    fn send_datagram(&self, data: &[u8]) -> Result<()>;
    fn recv_datagram<F: FnOnce(&[u8]) + Send>(
        &self,
        callback: F,
    ) -> impl Future<Output = Result<()>> + Send;
    fn max_datagram_size(&self) -> Option<usize>;
}
Expand description

Abstraction over a single QUIC connection.

QUIC library adapters (e.g. trillium-quinn) implement this trait. The generic HTTP/3 connection handler in server-common consumes it to manage streams without knowing about the underlying QUIC implementation.

Implementations should be cheaply cloneable (typically wrapping an Arc-based connection handle) since the connection handler clones this into spawned tasks.

Required Associated Types§

Source

type BidiStream: QuicTransportBidi + Unpin + Send + Sync + 'static

A bidirectional stream

Source

type RecvStream: QuicTransportReceive + Unpin + Send + Sync + 'static

A unidirectional receive stream from the peer

Source

type SendStream: QuicTransportSend + Unpin + Send + Sync + 'static

A unidirectional send stream to the peer

Required Methods§

Source

fn accept_bidi( &self, ) -> impl Future<Output = Result<(u64, Self::BidiStream)>> + Send

Accept the next bidirectional stream opened by the peer.

Returns the QUIC stream ID and a combined read/write transport.

Source

fn accept_uni( &self, ) -> impl Future<Output = Result<(u64, Self::RecvStream)>> + Send

Accept the next unidirectional stream opened by the peer.

Returns the QUIC stream ID and a receive-only stream.

Source

fn open_uni( &self, ) -> impl Future<Output = Result<(u64, Self::SendStream)>> + Send

Open a new unidirectional stream to the peer.

Returns the QUIC stream ID and a send-only stream.

Source

fn open_bidi( &self, ) -> impl Future<Output = Result<(u64, Self::BidiStream)>> + Send

Open a new bidirectional stream to the peer.

Returns the QUIC stream ID and a combined read/write transport.

Source

fn remote_address(&self) -> SocketAddr

The peer’s address.

Source

fn close(&self, error_code: u64, reason: &[u8])

Close the entire QUIC connection with an error code and reason.

Source

fn send_datagram(&self, data: &[u8]) -> Result<()>

Send an unreliable datagram over the QUIC connection.

Datagrams are atomic and unordered. The data must fit in a single QUIC packet (typically ~1200 bytes). Returns an error if datagrams are not supported by the peer or the data is too large.

Source

fn recv_datagram<F: FnOnce(&[u8]) + Send>( &self, callback: F, ) -> impl Future<Output = Result<()>> + Send

Receive the next unreliable datagram from the peer, passing the raw bytes to callback.

Source

fn max_datagram_size(&self) -> Option<usize>

The maximum datagram payload size the peer will accept, if datagrams are supported.

Returns None if the peer does not support datagrams.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§