UdpSocket

Struct UdpSocket 

Source
pub struct UdpSocket<const TIMER_HZ: u32, const L: usize> { /* private fields */ }
Expand description

A User Datagram Protocol socket.

A UDP socket is bound to a specific endpoint, and owns transmit and receive packet buffers.

Implementations§

Source§

impl<const TIMER_HZ: u32, const L: usize> UdpSocket<TIMER_HZ, L>

Source

pub fn new(socket_id: u8) -> UdpSocket<TIMER_HZ, L>

Create an UDP socket with the given buffers.

Source

pub fn handle(&self) -> SocketHandle

Return the socket handle.

Source

pub fn update_handle(&mut self, handle: SocketHandle)

Source

pub fn endpoint(&self) -> Option<SocketAddr>

Return the bound endpoint.

Source

pub fn state(&self) -> State

Return the connection state, in terms of the UDP connection.

Source

pub fn set_state(&mut self, state: State)

Source

pub fn should_update_available_data(&mut self, ts: Instant<TIMER_HZ>) -> bool

Source

pub fn recycle(&self, ts: Instant<TIMER_HZ>) -> bool

Source

pub fn closed_by_remote(&mut self, ts: Instant<TIMER_HZ>)

Source

pub fn set_available_data(&mut self, available_data: usize)

Set available data.

Source

pub fn get_available_data(&self) -> usize

Get the number of bytes available to ingress.

Source

pub fn rx_window(&self) -> usize

Source

pub fn bind<T: Into<SocketAddr>>(&mut self, endpoint: T) -> Result<(), Error>

Bind the socket to the given endpoint.

This function returns Err(Error::Illegal) if the socket was open (see is_open), and Err(Error::Unaddressable) if the port in the given endpoint is zero.

Source

pub fn is_open(&self) -> bool

Check whether the socket is open.

Source

pub fn can_recv(&self) -> bool

Check whether the receive buffer is full.

Source

pub fn recv<'b, F, R>(&'b mut self, f: F) -> Result<R, Error>
where F: FnOnce(&'b mut [u8]) -> (usize, R),

Dequeue a packet received from a remote endpoint, and return the endpoint as well as a pointer to the payload.

This function returns Err(Error::Exhausted) if the receive buffer is empty.

Source

pub fn recv_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>

Dequeue a packet received from a remote endpoint, copy the payload into the given slice, and return the amount of octets copied as well as the endpoint.

See also recv.

Source

pub fn rx_enqueue_slice(&mut self, data: &[u8]) -> usize

Source

pub fn peek(&mut self, size: usize) -> Result<&[u8], Error>

Peek at a packet received from a remote endpoint, and return the endpoint as well as a pointer to the payload without removing the packet from the receive buffer. This function otherwise behaves identically to recv.

It returns Err(Error::Exhausted) if the receive buffer is empty.

Source

pub fn peek_slice(&mut self, data: &mut [u8]) -> Result<usize, Error>

Peek at a packet received from a remote endpoint, copy the payload into the given slice, and return the amount of octets copied as well as the endpoint without removing the packet from the receive buffer. This function otherwise behaves identically to recv_slice.

See also peek.

Source

pub fn close(&mut self)

Trait Implementations§

Source§

impl<const TIMER_HZ: u32, const L: usize> AnySocket<TIMER_HZ, L> for UdpSocket<TIMER_HZ, L>

Source§

fn downcast( ref_: SocketRef<'_, Socket<TIMER_HZ, L>>, ) -> Result<SocketRef<'_, Self>, Error>

Source§

impl<const TIMER_HZ: u32, const L: usize> Debug for UdpSocket<TIMER_HZ, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const TIMER_HZ: u32, const L: usize> Into<Socket<TIMER_HZ, L>> for UdpSocket<TIMER_HZ, L>

Source§

fn into(self) -> Socket<TIMER_HZ, L>

Converts this type into the (usually inferred) input type.

Auto Trait Implementations§

§

impl<const TIMER_HZ: u32, const L: usize> Freeze for UdpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> RefUnwindSafe for UdpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Send for UdpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Sync for UdpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> Unpin for UdpSocket<TIMER_HZ, L>

§

impl<const TIMER_HZ: u32, const L: usize> UnwindSafe for UdpSocket<TIMER_HZ, L>

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.