pub trait AsyncUdpSocket:
Send
+ Sync
+ Debug
+ 'static {
// Required methods
fn create_io_poller(self: Arc<Self>) -> Pin<Box<dyn UdpPoller>>;
fn try_send(&self, transmit: &Transmit<'_>) -> Result<()>;
fn poll_recv(
&self,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>],
meta: &mut [RecvMeta],
) -> Poll<Result<usize>>;
fn local_addr(&self) -> Result<SocketAddr>;
// Provided methods
fn max_transmit_segments(&self) -> usize { ... }
fn max_receive_segments(&self) -> usize { ... }
fn may_fragment(&self) -> bool { ... }
}Expand description
Abstract implementation of a UDP socket for runtime independence
Required Methods§
Sourcefn create_io_poller(self: Arc<Self>) -> Pin<Box<dyn UdpPoller>>
fn create_io_poller(self: Arc<Self>) -> Pin<Box<dyn UdpPoller>>
Create a UdpPoller that can register a single task for write-readiness notifications
A poll_send method on a single object can usually store only one Waker at a time,
i.e. allow at most one caller to wait for an event. This method allows any number of
interested tasks to construct their own UdpPoller object. They can all then wait for the
same event and be notified concurrently, because each UdpPoller can store a separate
Waker.
Sourcefn try_send(&self, transmit: &Transmit<'_>) -> Result<()>
fn try_send(&self, transmit: &Transmit<'_>) -> Result<()>
Send UDP datagrams from transmits, or return WouldBlock and clear the underlying
socket’s readiness, or return an I/O error
If this returns io::ErrorKind::WouldBlock, UdpPoller::poll_writable must be called
to register the calling task to be woken when a send should be attempted again.
Sourcefn poll_recv(
&self,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>],
meta: &mut [RecvMeta],
) -> Poll<Result<usize>>
fn poll_recv( &self, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Poll<Result<usize>>
Receive UDP datagrams, or register to be woken if receiving may succeed in the future
Sourcefn local_addr(&self) -> Result<SocketAddr>
fn local_addr(&self) -> Result<SocketAddr>
Look up the local IP address and port used by this socket
Provided Methods§
Sourcefn max_transmit_segments(&self) -> usize
fn max_transmit_segments(&self) -> usize
Maximum number of datagrams that a Transmit may encode
Sourcefn max_receive_segments(&self) -> usize
fn max_receive_segments(&self) -> usize
Maximum number of datagrams that might be described by a single RecvMeta
Sourcefn may_fragment(&self) -> bool
fn may_fragment(&self) -> bool
Whether datagrams might get fragmented into multiple parts
Sockets should prevent this for best performance. See e.g. the IPV6_DONTFRAG socket
option.