[][src]Struct smoltcp::socket::UdpSocket

pub struct UdpSocket<'a, 'b: 'a> { /* fields omitted */ }

A User Datagram Protocol socket.

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

Methods

impl<'a, 'b> UdpSocket<'a, 'b>[src]

pub fn new(
    rx_buffer: UdpSocketBuffer<'a, 'b>,
    tx_buffer: UdpSocketBuffer<'a, 'b>
) -> UdpSocket<'a, 'b>
[src]

Create an UDP socket with the given buffers.

pub fn handle(&self) -> SocketHandle[src]

Return the socket handle.

pub fn endpoint(&self) -> IpEndpoint[src]

Return the bound endpoint.

pub fn hop_limit(&self) -> Option<u8>[src]

Return the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.

See also the set_hop_limit method

pub fn set_hop_limit(&mut self, hop_limit: Option<u8>)[src]

Set the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.

A socket without an explicitly set hop limit value uses the default IANA recommended value (64).

Panics

This function panics if a hop limit value of 0 is given. See RFC 1122 § 3.2.1.7.

pub fn bind<T: Into<IpEndpoint>>(&mut self, endpoint: T) -> Result<()>[src]

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.

pub fn is_open(&self) -> bool[src]

Check whether the socket is open.

pub fn can_send(&self) -> bool[src]

Check whether the transmit buffer is full.

pub fn can_recv(&self) -> bool[src]

Check whether the receive buffer is not empty.

pub fn packet_recv_capacity(&self) -> usize[src]

Return the maximum number packets the socket can receive.

pub fn packet_send_capacity(&self) -> usize[src]

Return the maximum number packets the socket can transmit.

pub fn payload_recv_capacity(&self) -> usize[src]

Return the maximum number of bytes inside the recv buffer.

pub fn payload_send_capacity(&self) -> usize[src]

Return the maximum number of bytes inside the transmit buffer.

pub fn send(&mut self, size: usize, endpoint: IpEndpoint) -> Result<&mut [u8]>[src]

Enqueue a packet to be sent to a given remote endpoint, and return a pointer to its payload.

This function returns Err(Error::Exhausted) if the transmit buffer is full, Err(Error::Unaddressable) if local or remote port, or remote address are unspecified, and Err(Error::Truncated) if there is not enough transmit buffer capacity to ever send this packet.

pub fn send_slice(&mut self, data: &[u8], endpoint: IpEndpoint) -> Result<()>[src]

Enqueue a packet to be sent to a given remote endpoint, and fill it from a slice.

See also send.

pub fn recv(&mut self) -> Result<(&[u8], IpEndpoint)>[src]

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.

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

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.

pub fn peek(&mut self) -> Result<(&[u8], &IpEndpoint)>[src]

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.

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

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.

Trait Implementations

impl<'a, 'b> AnySocket<'a, 'b> for UdpSocket<'a, 'b>[src]

impl<'a, 'b: 'a> Debug for UdpSocket<'a, 'b>[src]

impl<'a, 'b> Into<Socket<'a, 'b>> for UdpSocket<'a, 'b>[src]

Auto Trait Implementations

impl<'a, 'b> RefUnwindSafe for UdpSocket<'a, 'b>

impl<'a, 'b> Send for UdpSocket<'a, 'b>

impl<'a, 'b> Sync for UdpSocket<'a, 'b>

impl<'a, 'b> Unpin for UdpSocket<'a, 'b>

impl<'a, 'b> !UnwindSafe for UdpSocket<'a, 'b>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.