pub trait DatagramSocketSend: Sync {
// Required methods
fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>;
fn poll_send_to(
&self,
cx: &mut Context<'_>,
buf: &[u8],
addr: SocketAddr,
) -> Poll<Result<usize>>;
// Provided methods
fn poll_send_many(
&self,
cx: &mut Context<'_>,
bufs: &[ReadBuf<'_>],
) -> Poll<Result<usize>> { ... }
fn as_udp_socket(&self) -> Option<&UdpSocket> { ... }
fn peer_addr(&self) -> Option<SocketAddr> { ... }
}Expand description
Describes the send half of a connected datagram socket.
Required Methods§
Sourcefn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
fn poll_send(&self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
Attempts to send data on the socket to the remote address to which it was previously connected.
Note that on multiple calls to a poll_* method in the send direction,
only the Waker from the Context passed to the most recent call will
be scheduled to receive a wakeup.
§Return value
The function returns:
Poll::Pendingif the socket is not available to writePoll::Ready(Ok(n))nis the number of bytes sentPoll::Ready(Err(e))if an error is encountered.
§Errors
This function may encounter any standard I/O error except WouldBlock.
Sourcefn 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>>
Attempts to send data on the socket to a given address.
If this socket only supports a single address, it should forward to
send. It should not panic or discard the data.
It’s recommended that this return an error if addr doesn’t match the
only supported address.
Note that on multiple calls to a poll_* method in the send direction,
only the Waker from the Context passed to the most recent call
will be scheduled to receive a wakeup.
§Return value
The function returns:
Poll::Pendingif the socket is not ready to writePoll::Ready(Ok(n))nis the number of bytes sent.Poll::Ready(Err(e))if an error is encountered.
§Errors
This function may encounter any standard I/O error except WouldBlock.
Provided Methods§
Sourcefn 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>>
Attempts to send multiple packets of data on the socket to the remote address to which it was previously connected.
Note that on multiple calls to a poll_* method in the send direction,
only the Waker from the Context passed to the most recent call
will be scheduled to receive a wakeup.
§Return value
The function returns:
Poll::Pendingif the socket is not ready to writePoll::Ready(Ok(n))nis the number of packets sent. If any packet was sent only partially, that information is lost.Poll::Ready(Err(e))if an error is encountered.
§Errors
This function may encounter any standard I/O error except WouldBlock.
Sourcefn as_udp_socket(&self) -> Option<&UdpSocket>
fn as_udp_socket(&self) -> Option<&UdpSocket>
If the underlying socket is a UdpSocket, return the reference to it.
Sourcefn peer_addr(&self) -> Option<SocketAddr>
fn peer_addr(&self) -> Option<SocketAddr>
Returns the socket address of the remote peer this socket was connected to.