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
Udp(UdpSocket<'a, 'b>)
Tcp(TcpSocket<'a>)
Methods
impl<'a, 'b> Socket<'a, 'b>
[src]
fn debug_id(&self) -> usize
Return the debug identifier.
fn set_debug_id(&mut self, id: usize)
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.
fn process(&mut self,
timestamp: u64,
ip_repr: &IpRepr,
payload: &[u8])
-> Result<(), Error>
timestamp: u64,
ip_repr: &IpRepr,
payload: &[u8])
-> Result<(), Error>
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.
fn dispatch<F, R>(&mut self, timestamp: u64, emit: &mut F) -> Result<R, Error> where F: FnMut(&IpRepr, &IpPayload) -> Result<R, Error>
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.