pub trait DatagramSocket: Send {
// Required methods
fn poll_recv_from(
&mut self,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<(usize, SocketAddr)>>;
fn poll_send_to(
&mut self,
cx: &mut Context<'_>,
buf: &[u8],
peer: SocketAddr,
) -> Poll<Result<usize>>;
fn local_addr(&self) -> Result<SocketAddr>;
// Provided methods
fn poll_recv_batch(
&mut self,
cx: &mut Context<'_>,
bufs: &mut [&mut [u8]],
out_meta: &mut [(usize, SocketAddr)],
) -> Poll<Result<usize>> { ... }
fn poll_send_batch(
&mut self,
cx: &mut Context<'_>,
packets: &[(&[u8], SocketAddr)],
) -> Poll<Result<usize>> { ... }
}Expand description
A bound datagram (UDP) socket pinned to the worker that created it.
Send-but-!Sync for the same reason as TcpAcceptor: prime’s reactor
registration is per-worker. A QUIC/h3 listener demuxes many connections over
this one socket, so poll it only on the worker that produced it.
Required Methods§
Sourcefn poll_recv_from(
&mut self,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<Result<(usize, SocketAddr)>>
fn poll_recv_from( &mut self, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<(usize, SocketAddr)>>
Receive one datagram into buf; yields (len, sender).
Sourcefn poll_send_to(
&mut self,
cx: &mut Context<'_>,
buf: &[u8],
peer: SocketAddr,
) -> Poll<Result<usize>>
fn poll_send_to( &mut self, cx: &mut Context<'_>, buf: &[u8], peer: SocketAddr, ) -> Poll<Result<usize>>
Send buf to peer; Pending when the kernel send buffer is full.
Sourcefn local_addr(&self) -> Result<SocketAddr>
fn local_addr(&self) -> Result<SocketAddr>
The local address the socket bound to.
Provided Methods§
Sourcefn poll_recv_batch(
&mut self,
cx: &mut Context<'_>,
bufs: &mut [&mut [u8]],
out_meta: &mut [(usize, SocketAddr)],
) -> Poll<Result<usize>>
fn poll_recv_batch( &mut self, cx: &mut Context<'_>, bufs: &mut [&mut [u8]], out_meta: &mut [(usize, SocketAddr)], ) -> Poll<Result<usize>>
Receive up to min(bufs.len(), out_meta.len()) datagrams at once,
writing each datagram’s (len, sender) into out_meta and returning
the count. The default loops poll_recv_from;
a backend that can pull many datagrams per syscall (prime’s recvmmsg)
overrides this to amortize the kernel-entry cost across the burst.
Sourcefn poll_send_batch(
&mut self,
cx: &mut Context<'_>,
packets: &[(&[u8], SocketAddr)],
) -> Poll<Result<usize>>
fn poll_send_batch( &mut self, cx: &mut Context<'_>, packets: &[(&[u8], SocketAddr)], ) -> Poll<Result<usize>>
Send all packets (each (bytes, peer)) in as few syscalls as
possible, returning the count accepted. The default loops
poll_send_to; prime overrides with sendmmsg.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".