pub struct UdpSocketState { /* private fields */ }
Expand description
Tokio-compatible UDP socket with some useful specializations.
Unlike a standard tokio UDP socket, this allows ECN bits to be read and written on some platforms.
Implementations§
Source§impl UdpSocketState
impl UdpSocketState
pub fn new(sock: UdpSockRef<'_>) -> Result<Self>
Sourcepub fn send(
&self,
socket: UdpSockRef<'_>,
transmit: &Transmit<'_>,
) -> Result<()>
pub fn send( &self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>, ) -> Result<()>
Sends a Transmit
on the given socket.
This function will only ever return errors of kind io::ErrorKind::WouldBlock
.
All other errors will be logged and converted to Ok
.
UDP transmission errors are considered non-fatal because higher-level protocols must employ retransmits and timeouts anyway in order to deal with UDP’s unreliable nature. Thus, logging is most likely the only thing you can do with these errors.
If you would like to handle these errors yourself, use UdpSocketState::try_send
instead.
Sourcepub fn try_send(
&self,
socket: UdpSockRef<'_>,
transmit: &Transmit<'_>,
) -> Result<()>
pub fn try_send( &self, socket: UdpSockRef<'_>, transmit: &Transmit<'_>, ) -> Result<()>
Sends a Transmit
on the given socket without any additional error handling.
pub fn recv( &self, socket: UdpSockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Result<usize>
Sourcepub fn max_gso_segments(&self) -> usize
pub fn max_gso_segments(&self) -> usize
The maximum amount of segments which can be transmitted if a platform supports Generic Send Offload (GSO).
This is 1 if the platform doesn’t support GSO. Subject to change if errors are detected while using GSO.
Sourcepub fn gro_segments(&self) -> usize
pub fn gro_segments(&self) -> usize
The number of segments to read when GRO is enabled. Used as a factor to compute the receive buffer size.
Returns 1 if the platform doesn’t support GRO.
Sourcepub fn set_send_buffer_size(
&self,
socket: UdpSockRef<'_>,
bytes: usize,
) -> Result<()>
pub fn set_send_buffer_size( &self, socket: UdpSockRef<'_>, bytes: usize, ) -> Result<()>
Resize the send buffer of socket
to bytes
Sourcepub fn set_recv_buffer_size(
&self,
socket: UdpSockRef<'_>,
bytes: usize,
) -> Result<()>
pub fn set_recv_buffer_size( &self, socket: UdpSockRef<'_>, bytes: usize, ) -> Result<()>
Resize the receive buffer of socket
to bytes
Sourcepub fn send_buffer_size(&self, socket: UdpSockRef<'_>) -> Result<usize>
pub fn send_buffer_size(&self, socket: UdpSockRef<'_>) -> Result<usize>
Get the size of the socket
send buffer
Sourcepub fn recv_buffer_size(&self, socket: UdpSockRef<'_>) -> Result<usize>
pub fn recv_buffer_size(&self, socket: UdpSockRef<'_>) -> Result<usize>
Get the size of the socket
receive buffer
Sourcepub fn may_fragment(&self) -> bool
pub fn may_fragment(&self) -> bool
Whether transmitted datagrams might get fragmented by the IP layer
Returns false
on targets which employ e.g. the IPV6_DONTFRAG
socket option.