Skip to main content

AsyncUdpSocket

Trait AsyncUdpSocket 

Source
pub trait AsyncUdpSocket:
    Send
    + Sync
    + Debug {
    // Required methods
    fn poll_send(
        &self,
        cx: &mut Context<'_>,
        transmit: &Transmit<'_>,
    ) -> Poll<Result<usize>>;
    fn poll_recv(
        &self,
        cx: &mut Context<'_>,
        bufs: &mut [IoSliceMut<'_>],
        meta: &mut [RecvMeta],
    ) -> Poll<Result<usize>>;
    fn local_addr(&self) -> Result<SocketAddr>;
    fn traffic_class(&self) -> Result<u32>;

    // Provided methods
    fn max_receive_batch(&self) -> usize { ... }
    fn unmarked(&self) -> bool { ... }
}
Expand description

A UDP socket of a runtime, in the poll form of quinn-udp’s so that batched send and receive (sendmmsg, recvmmsg, GSO, GRO) fit.

Required Methods§

Source

fn poll_send( &self, cx: &mut Context<'_>, transmit: &Transmit<'_>, ) -> Poll<Result<usize>>

Sends transmit, marked with its traffic_class. Pending when the socket cannot take it now (the driver then counts it lost, as UDP would).

Source

fn poll_recv( &self, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Poll<Result<usize>>

Receives up to bufs.len() datagrams (at most max_receive_batch), filling meta alongside; how many.

Source

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

The address it is bound to.

Source

fn traffic_class(&self) -> Result<u32>

The TOS / Traffic Class byte the operating system reports for the socket (getsockopt of IP_TOS / IPV6_TCLASS): what its next datagram carries.

§Errors

The option is not offered on this platform.

Provided Methods§

Source

fn max_receive_batch(&self) -> usize

How many buffers one poll_recv can fill. 1 by default.

Source

fn unmarked(&self) -> bool

Whether the platform refused to mark this socket: its datagrams leave with traffic class 0 whatever the transmit asks (see crate::sockets::set_traffic_class).

Implementations§

Source§

impl<'a> dyn AsyncUdpSocket + 'a

Source

pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>

Waits for one datagram: its length and sender.

Source

pub async fn send_to( &self, buf: &[u8], destination: SocketAddr, ) -> Result<usize>

Sends one datagram, unmarked, waiting for room.

Source

pub fn try_send(&self, transmit: &Transmit<'_>) -> Result<usize>

Sends transmit if the socket can take it now: how many bytes, or the system’s error (WouldBlock when the socket cannot take it now).

§Errors

The send failed, or would block.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§