pub struct UdpSocket { /* private fields */ }Expand description
Wrapper around a tokio UDP socket.
Implementations§
Source§impl UdpSocket
impl UdpSocket
Sourcepub fn bind_local_v4(port: u16) -> Result<Self>
pub fn bind_local_v4(port: u16) -> Result<Self>
Bind only Ipv4 on localhost.
Sourcepub fn bind_local_v6(port: u16) -> Result<Self>
pub fn bind_local_v6(port: u16) -> Result<Self>
Bind only Ipv6 on localhost.
Sourcepub fn bind_local(network: IpFamily, port: u16) -> Result<Self>
pub fn bind_local(network: IpFamily, port: u16) -> Result<Self>
Bind to the given port only on localhost.
Sourcepub fn bind(network: IpFamily, port: u16) -> Result<Self>
pub fn bind(network: IpFamily, port: u16) -> Result<Self>
Bind to the given port and listen on all interfaces.
Sourcepub fn bind_full(addr: impl Into<SocketAddr>) -> Result<Self>
pub fn bind_full(addr: impl Into<SocketAddr>) -> Result<Self>
Bind to any provided SocketAddr.
Sourcepub fn recv<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFut<'a, 'b>
pub fn recv<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFut<'a, 'b>
Receives a single datagram message on the socket from the remote address to which it is connected. On success, returns the number of bytes read.
The function must be called with valid byte array buf of sufficient
size to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.
The connect method will connect this socket to a remote address.
This method will fail if the socket is not connected.
Sourcepub fn recv_from<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFromFut<'a, 'b>
pub fn recv_from<'a, 'b>(&'b self, buffer: &'a mut [u8]) -> RecvFromFut<'a, 'b>
Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin.
The function must be called with valid byte array buf of sufficient
size to hold the message bytes. If a message is too long to fit in the
supplied buffer, excess bytes may be discarded.
Sourcepub fn send<'a, 'b>(&'b self, buffer: &'a [u8]) -> SendFut<'a, 'b>
pub fn send<'a, 'b>(&'b self, buffer: &'a [u8]) -> SendFut<'a, 'b>
Sends data on the socket to the remote address that the socket is connected to.
The connect method will connect this socket to a remote address.
This method will fail if the socket is not connected.
§Return
On success, the number of bytes sent is returned, otherwise, the encountered error is returned.
Sourcepub fn send_to<'a, 'b>(
&'b self,
buffer: &'a [u8],
to: SocketAddr,
) -> SendToFut<'a, 'b>
pub fn send_to<'a, 'b>( &'b self, buffer: &'a [u8], to: SocketAddr, ) -> SendToFut<'a, 'b>
Sends data on the socket to the given address. On success, returns the number of bytes written.
Sourcepub fn connect(&self, addr: SocketAddr) -> Result<()>
pub fn connect(&self, addr: SocketAddr) -> Result<()>
Connects the UDP socket setting the default destination for send() and
limiting packets that are read via recv from the address specified in
addr.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Returns the local address of this socket.
Sourcepub async fn close(&self)
pub async fn close(&self)
Closes the socket, and waits for the underlying libc::close call to be finished.
Sourcepub fn try_send_quinn(&self, transmit: &Transmit<'_>) -> Result<()>
pub fn try_send_quinn(&self, transmit: &Transmit<'_>) -> Result<()>
Send a quinn based Transmit.
Sourcepub fn poll_send_quinn(
&self,
cx: &mut Context<'_>,
transmit: &Transmit<'_>,
) -> Poll<Result<()>>
pub fn poll_send_quinn( &self, cx: &mut Context<'_>, transmit: &Transmit<'_>, ) -> Poll<Result<()>>
poll send a quinn based Transmit.
Sourcepub fn poll_recv_quinn(
&self,
cx: &mut Context<'_>,
bufs: &mut [IoSliceMut<'_>],
meta: &mut [RecvMeta],
) -> Poll<Result<usize>>
pub fn poll_recv_quinn( &self, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta], ) -> Poll<Result<usize>>
quinn based poll_recv
Sourcepub fn create_sender(self: Arc<Self>) -> UdpSender
pub fn create_sender(self: Arc<Self>) -> UdpSender
Creates a UdpSender sender.
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.
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.