Struct axnet::UdpSocket

source ·
pub struct UdpSocket { /* private fields */ }
Expand description

A UDP socket that provides POSIX-like APIs.

Implementations§

source§

impl UdpSocket

source

pub fn new() -> Self

Creates a new UDP socket.

source

pub fn local_addr(&self) -> AxResult<SocketAddr>

Returns the local address and port, or Err(NotConnected) if not connected.

source

pub fn peer_addr(&self) -> AxResult<SocketAddr>

Returns the remote address and port, or Err(NotConnected) if not connected.

source

pub fn is_nonblocking(&self) -> bool

Returns whether this socket is in nonblocking mode.

source

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.

source

pub fn bind(&self, local_addr: SocketAddr) -> AxResult

Binds an unbound socket to the given address and port.

It’s must be called before send_to and recv_from.

source

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.

source

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.

source

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.

source

pub fn connect(&self, addr: SocketAddr) -> AxResult

Connects this UDP socket to a remote address, allowing the send and recv to be used to send data and also applies filters to only receive data from the specified address.

The local port will be generated automatically if the socket is not bound. It’s must be called before send and recv.

source

pub fn send(&self, buf: &[u8]) -> AxResult<usize>

Sends data on the socket to the remote address to which it is connected.

source

pub fn recv(&self, buf: &mut [u8]) -> AxResult<usize>

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.

source

pub fn shutdown(&self) -> AxResult

Close the socket.

source

pub fn poll(&self) -> AxResult<PollState>

Whether the socket is readable or writable.

Trait Implementations§

source§

impl Drop for UdpSocket

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.