Enum smoltcp::socket::Socket [] [src]

pub enum Socket<'a, 'b: 'a> {
    Udp(UdpSocket<'a, 'b>),
    Tcp(TcpSocket<'a>),
    // some variants omitted
}

A network socket.

This enumeration abstracts the various types of sockets based on the IP protocol. To downcast a Socket value down to a concrete socket, use the AsSocket trait, and call e.g. socket.as_socket::<UdpSocket<_>>().

The process and dispatch functions are fundamentally asymmetric and thus differ in their use of the trait PacketRepr. When process is called, the packet length is already known and no allocation is required; on the other hand, process would have to downcast a &PacketRepr to e.g. an &UdpRepr through Any, which is rather inelegant. Conversely, when dispatch is called, the packet length is not yet known and the packet storage has to be allocated; but the &PacketRepr is sufficient since the lower layers treat the packet as an opaque octet sequence.

Variants

Methods

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

Return the debug identifier.

Set the debug identifier.

The debug identifier is a number printed in socket trace messages. It could as well be used by the user code.

Process a packet received from a network interface.

This function checks if the packet contained in the payload matches the socket endpoint, and if it does, copies it into the internal buffer, otherwise, Err(Error::Rejected) is returned.

This function is used internally by the networking stack.

Prepare a packet to be transmitted to a network interface.

This function checks if the internal buffer is empty, and if it is not, calls f with the representation of the packet to be transmitted, otherwise, Err(Error::Exhausted) is returned.

This function is used internally by the networking stack.

Trait Implementations

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

Formats the value using the given formatter.

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

impl<'a, 'b> AsSocket<TcpSocket<'a>> for Socket<'a, 'b>
[src]