Skip to main content

UdpTransport

Trait UdpTransport 

Source
pub trait UdpTransport:
    Send
    + Sync
    + Debug
    + Sized
    + 'static {
    // Required methods
    fn from_std(socket: UdpSocket) -> Result<Self>;
    fn local_addr(&self) -> Result<SocketAddr>;
    fn poll_recv_io<R>(
        &self,
        cx: &mut Context<'_>,
        recv: impl FnMut(&Self) -> Result<R>,
    ) -> Poll<Result<R>>;
    fn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>;
    fn try_send_io<R>(&self, send: impl FnOnce(&Self) -> Result<R>) -> Result<R>;

    // Provided methods
    fn max_transmit_segments(&self) -> usize { ... }
    fn max_receive_segments(&self) -> usize { ... }
    fn may_fragment(&self) -> bool { ... }
}
Expand description

Async UDP socket abstraction for QUIC transport.

Runtime adapters implement this for their platform’s async UDP type. QUIC library adapters (e.g. trillium-quinn) consume this to bridge to their own socket traits.

The poll_recv_io and try_send_io methods pass &Self to the caller’s closure, allowing the caller to access platform-specific traits (e.g. AsFd on unix, AsSocket on windows) without those traits appearing in this trait’s definition.

Runtimes that do not support UDP can use () as their UdpTransport type — it returns errors from all operations.

Required Methods§

Source

fn from_std(socket: UdpSocket) -> Result<Self>

Wrap a bound, non-blocking std UDP socket into this async type.

Source

fn local_addr(&self) -> Result<SocketAddr>

The local address this socket is bound to.

Source

fn poll_recv_io<R>( &self, cx: &mut Context<'_>, recv: impl FnMut(&Self) -> Result<R>, ) -> Poll<Result<R>>

Poll for read readiness, then attempt a receive operation.

When the socket is readable, calls recv with &self. If recv returns ErrorKind::WouldBlock, the implementation clears readiness and re-polls on the next call.

Source

fn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>

Poll for write readiness without attempting any I/O.

Used by QUIC implementations that separate readiness polling from the send attempt (e.g. quinn’s multi-sender pattern).

Source

fn try_send_io<R>(&self, send: impl FnOnce(&Self) -> Result<R>) -> Result<R>

Attempt a send operation, managing readiness state.

Calls send with &self. On ErrorKind::WouldBlock, the implementation ensures the next poll_writable call returns Poll::Pending.

Provided Methods§

Source

fn max_transmit_segments(&self) -> usize

Maximum number of datagrams to send in a single syscall (GSO).

Source

fn max_receive_segments(&self) -> usize

Maximum number of datagrams to receive in a single syscall (GRO).

Source

fn may_fragment(&self) -> bool

Whether outbound datagrams may be fragmented by the network layer.

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.

Implementations on Foreign Types§

Source§

impl UdpTransport for ()

Source§

fn from_std(_: UdpSocket) -> Result<Self>

Source§

fn local_addr(&self) -> Result<SocketAddr>

Source§

fn poll_recv_io<R>( &self, _: &mut Context<'_>, _: impl FnMut(&Self) -> Result<R>, ) -> Poll<Result<R>>

Source§

fn poll_writable(&self, _: &mut Context<'_>) -> Poll<Result<()>>

Source§

fn try_send_io<R>(&self, _: impl FnOnce(&Self) -> Result<R>) -> Result<R>

Implementors§