pub struct MaybeConnectedSocket<T> { /* private fields */ }
Expand description
A cheap wrapper around a datagram socket which describes if it is connected to an explicit peer.
This struct essentially forwards its underlying socket’s send_to()
method
to send()
if the socket is explicitly connected to a peer. This is helpful
for preventing issues on platforms that do not support send_to
on
already-connected sockets.
§Warning
A socket’s “connectedness” is determined once, when it is created. If the
socket is created as connected, then later disconnected from its peer, its
send_to()
call will fail.
For example, MacOS errors if send_to
is used on a socket that’s already
connected. Only send
can be used. By using MaybeConnectedSocket
, you can
use the same send
and send_to
APIs in both client- and server-side code.
Clients, usually with connected sockets, will then forward send_to
to
send
, whereas servers, usually with unconnected sockets, will use
send_to
.
Implementations§
Source§impl<T: DatagramSocketSend> MaybeConnectedSocket<T>
impl<T: DatagramSocketSend> MaybeConnectedSocket<T>
Trait Implementations§
Source§impl<T: Clone> Clone for MaybeConnectedSocket<T>
impl<T: Clone> Clone for MaybeConnectedSocket<T>
Source§fn clone(&self) -> MaybeConnectedSocket<T>
fn clone(&self) -> MaybeConnectedSocket<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: DatagramSocketSend> DatagramSocketSend for MaybeConnectedSocket<T>
impl<T: DatagramSocketSend> DatagramSocketSend for MaybeConnectedSocket<T>
Source§fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
Source§fn poll_send_to(
&self,
cx: &mut Context<'_>,
buf: &[u8],
addr: SocketAddr,
) -> Poll<Result<usize>>
fn poll_send_to( &self, cx: &mut Context<'_>, buf: &[u8], addr: SocketAddr, ) -> Poll<Result<usize>>
Source§fn poll_send_many(
&self,
cx: &mut Context<'_>,
bufs: &[ReadBuf<'_>],
) -> Poll<Result<usize>>
fn poll_send_many( &self, cx: &mut Context<'_>, bufs: &[ReadBuf<'_>], ) -> Poll<Result<usize>>
Source§fn as_udp_socket(&self) -> Option<&UdpSocket>
fn as_udp_socket(&self) -> Option<&UdpSocket>
UdpSocket
, return the reference to it.