pub struct DatagramContext<W> { /* private fields */ }Expand description
Context passed to a UDP crate::DatagramHandler.
Writes through this context are staged in a handler-local outbox. They are
encoded into the socket’s pending datagram queue when the handler returns.
They are sent only when Self::flush or a *_and_flush method requests
an immediate flush. Dropping a flush handle is fire-and-forget; awaiting it
waits until the local send_to calls complete.
Implementations§
Source§impl<W: Send + 'static> DatagramContext<W>
impl<W: Send + 'static> DatagramContext<W>
Sourcepub fn peer_addr(&self) -> SocketAddr
pub fn peer_addr(&self) -> SocketAddr
Peer address for the current datagram.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Local socket address.
Sourcepub fn channel(&self) -> DatagramChannel<W>
pub fn channel(&self) -> DatagramChannel<W>
Returns a cloneable channel for writing from outside the current handler.
Sourcepub fn write(&mut self, msg: W) -> DatagramWriteHandle
pub fn write(&mut self, msg: W) -> DatagramWriteHandle
Stages a response to the current datagram peer.
The message is stored in the handler-local outbox and later encoded into the socket’s pending datagram queue. It is not sent until the outbox or channel is explicitly flushed.
Sourcepub fn write_to(&mut self, peer_addr: SocketAddr, msg: W) -> DatagramWriteHandle
pub fn write_to(&mut self, peer_addr: SocketAddr, msg: W) -> DatagramWriteHandle
Stages a datagram for an explicit peer.
Use this when a handler needs to reply somewhere other than the sender of the current datagram.
Sourcepub fn flush(&mut self) -> DatagramFlushHandle<'_, W>
pub fn flush(&mut self) -> DatagramFlushHandle<'_, W>
Sends messages staged by this handler so far.
Dropping the returned handle is fire-and-forget. Awaiting it waits until
the socket task completes send_to for all staged messages before this
flush boundary.
Sourcepub fn write_and_flush(&mut self, msg: W) -> DatagramFlushHandle<'_, W>
pub fn write_and_flush(&mut self, msg: W) -> DatagramFlushHandle<'_, W>
Stages a response to the current peer and requests a flush.
Sourcepub fn write_to_and_flush(
&mut self,
peer_addr: SocketAddr,
msg: W,
) -> DatagramFlushHandle<'_, W>
pub fn write_to_and_flush( &mut self, peer_addr: SocketAddr, msg: W, ) -> DatagramFlushHandle<'_, W>
Stages a datagram for an explicit peer and requests a flush.