pub struct UdpCtx { /* private fields */ }Expand description
Async context for a UDP socket. Async context for a UDP socket.
Passed to AsyncEventHandler::on_udp_bind()
for each bound UDP socket. Provides async recv and fire-and-forget send.
Implementations§
Source§impl UdpCtx
impl UdpCtx
Sourcepub fn recv_from(&self) -> UdpRecvFuture ⓘ
pub fn recv_from(&self) -> UdpRecvFuture ⓘ
Receive a datagram, returning the payload and source address.
Suspends until a datagram is available. Each call returns exactly one
datagram. The payload is copied into a Vec<u8> (datagrams are
typically small, so this is acceptable for the initial implementation).
Sourcepub fn send_ready(&self) -> UdpSendReadyFuture
pub fn send_ready(&self) -> UdpSendReadyFuture
Resolve when at least one UDP send slot is available on this socket.
Use this to back off when UdpCtx::send_to returns
crate::error::UdpSendError::PoolExhausted, rather than busy-looping.
On the io_uring backend the future suspends until a completion frees
a slot. On the mio backend sends are synchronous and this future is
always immediately ready — callers can still use it to stay
backend-agnostic.
Only one task should await this per socket at a time; a second waiter overwrites the first, which is then leaked (it must still be driven from another wake source).
Sourcepub fn send_to(&self, peer: SocketAddr, data: &[u8]) -> Result<(), UdpSendError>
pub fn send_to(&self, peer: SocketAddr, data: &[u8]) -> Result<(), UdpSendError>
Send a datagram to the given peer (mio backend — synchronous non-blocking send).
WouldBlock is surfaced as crate::error::UdpSendError::PoolExhausted so callers
have a single “try again later” branch that matches the io_uring backend.