pub struct UdpSocket { /* private fields */ }
Expand description
A UDP socket that provides POSIX-like APIs.
Implementations§
source§impl UdpSocket
impl UdpSocket
sourcepub fn local_addr(&self) -> AxResult<SocketAddr>
pub fn local_addr(&self) -> AxResult<SocketAddr>
Returns the local address and port, or
Err(NotConnected)
if not connected.
sourcepub fn peer_addr(&self) -> AxResult<SocketAddr>
pub fn peer_addr(&self) -> AxResult<SocketAddr>
Returns the remote address and port, or
Err(NotConnected)
if not connected.
sourcepub fn is_nonblocking(&self) -> bool
pub fn is_nonblocking(&self) -> bool
Returns whether this socket is in nonblocking mode.
sourcepub fn set_nonblocking(&self, nonblocking: bool)
pub fn set_nonblocking(&self, nonblocking: bool)
Moves this UDP socket into or out of nonblocking mode.
This will result in recv
, recv_from
, send
, and send_to
operations becoming nonblocking, i.e., immediately returning from their
calls. If the IO operation is successful, Ok
is returned and no
further action is required. If the IO operation could not be completed
and needs to be retried, an error with kind
Err(WouldBlock)
is returned.
sourcepub fn bind(&self, local_addr: SocketAddr) -> AxResult
pub fn bind(&self, local_addr: SocketAddr) -> AxResult
sourcepub fn send_to(&self, buf: &[u8], remote_addr: SocketAddr) -> AxResult<usize>
pub fn send_to(&self, buf: &[u8], remote_addr: SocketAddr) -> AxResult<usize>
Sends data on the socket to the given address. On success, returns the number of bytes written.
sourcepub fn recv_from(&self, buf: &mut [u8]) -> AxResult<(usize, SocketAddr)>
pub fn recv_from(&self, buf: &mut [u8]) -> AxResult<(usize, SocketAddr)>
Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin.
sourcepub fn peek_from(&self, buf: &mut [u8]) -> AxResult<(usize, SocketAddr)>
pub fn peek_from(&self, buf: &mut [u8]) -> AxResult<(usize, SocketAddr)>
Receives a single datagram message on the socket, without removing it from the queue. On success, returns the number of bytes read and the origin.
sourcepub fn connect(&self, addr: SocketAddr) -> AxResult
pub fn connect(&self, addr: SocketAddr) -> AxResult
sourcepub fn send(&self, buf: &[u8]) -> AxResult<usize>
pub fn send(&self, buf: &[u8]) -> AxResult<usize>
Sends data on the socket to the remote address to which it is connected.