Преглед на файлове

socket: move meta from XxxSocket to SocketSetItem.

Dario Nieuwenhuis преди 3 години
родител
ревизия
ff47259603
променени са 9 файла, в които са добавени 148 реда и са изтрити 344 реда
  1. 45 29
      src/iface/interface.rs
  2. 2 17
      src/socket/dhcpv4.rs
  3. 6 30
      src/socket/icmp.rs
  4. 1 1
      src/socket/meta.rs
  5. 13 36
      src/socket/mod.rs
  6. 6 26
      src/socket/raw.rs
  7. 15 60
      src/socket/set.rs
  8. 54 118
      src/socket/tcp.rs
  9. 6 27
      src/socket/udp.rs

+ 45 - 29
src/iface/interface.rs

@@ -474,10 +474,7 @@ where
     ///
     /// # Panics
     /// This function panics if the storage is fixed-size (not a `Vec`) and is full.
-    pub fn add_socket<T>(&mut self, socket: T) -> SocketHandle
-    where
-        T: Into<Socket<'a>>,
-    {
+    pub fn add_socket<T: AnySocket<'a>>(&mut self, socket: T) -> SocketHandle {
         self.sockets.add(socket)
     }
 
@@ -558,12 +555,12 @@ where
 
     /// Get an iterator to the inner sockets.
     pub fn sockets(&self) -> impl Iterator<Item = &Socket<'a>> {
-        self.sockets.iter()
+        self.sockets.iter().map(|i| &i.socket)
     }
 
     /// Get a mutable iterator to the inner sockets.
     pub fn sockets_mut(&mut self) -> impl Iterator<Item = &mut Socket<'a>> {
-        self.sockets.iter_mut()
+        self.sockets.iter_mut().map(|i| &mut i.socket)
     }
 
     /// Add an address to a list of subscribed multicast IP addresses.
@@ -733,9 +730,9 @@ where
 
         self.sockets
             .iter()
-            .filter_map(|socket| {
-                let socket_poll_at = socket.poll_at(&cx);
-                match socket.meta().poll_at(socket_poll_at, |ip_addr| {
+            .filter_map(|item| {
+                let socket_poll_at = item.socket.poll_at(&cx);
+                match item.meta.poll_at(socket_poll_at, |ip_addr| {
                     self.inner.has_neighbor(&cx, &ip_addr)
                 }) {
                     PollAt::Ingress => None,
@@ -841,9 +838,9 @@ where
         let _caps = device.capabilities();
 
         let mut emitted_any = false;
-        for socket in sockets.iter_mut() {
-            if !socket
-                .meta_mut()
+        for item in sockets.iter_mut() {
+            if !item
+                .meta
                 .egress_permitted(cx.now, |ip_addr| inner.has_neighbor(cx, &ip_addr))
             {
                 continue;
@@ -862,13 +859,13 @@ where
                 }};
             }
 
-            let socket_result = match *socket {
+            let socket_result = match &mut item.socket {
                 #[cfg(feature = "socket-raw")]
-                Socket::Raw(ref mut socket) => {
+                Socket::Raw(socket) => {
                     socket.dispatch(cx, |response| respond!(IpPacket::Raw(response)))
                 }
                 #[cfg(feature = "socket-icmp")]
-                Socket::Icmp(ref mut socket) => socket.dispatch(cx, |response| match response {
+                Socket::Icmp(socket) => socket.dispatch(cx, |response| match response {
                     #[cfg(feature = "proto-ipv4")]
                     (IpRepr::Ipv4(ipv4_repr), IcmpRepr::Ipv4(icmpv4_repr)) => {
                         respond!(IpPacket::Icmpv4((ipv4_repr, icmpv4_repr)))
@@ -880,15 +877,15 @@ where
                     _ => Err(Error::Unaddressable),
                 }),
                 #[cfg(feature = "socket-udp")]
-                Socket::Udp(ref mut socket) => {
+                Socket::Udp(socket) => {
                     socket.dispatch(cx, |response| respond!(IpPacket::Udp(response)))
                 }
                 #[cfg(feature = "socket-tcp")]
-                Socket::Tcp(ref mut socket) => {
+                Socket::Tcp(socket) => {
                     socket.dispatch(cx, |response| respond!(IpPacket::Tcp(response)))
                 }
                 #[cfg(feature = "socket-dhcpv4")]
-                Socket::Dhcpv4(ref mut socket) => {
+                Socket::Dhcpv4(socket) => {
                     socket.dispatch(cx, |response| respond!(IpPacket::Dhcpv4(response)))
                 }
             };
@@ -901,15 +898,14 @@ where
                     // requests from the socket. However, without an additional rate limiting
                     // mechanism, we would spin on every socket that has yet to discover its
                     // neighboor.
-                    socket
-                        .meta_mut()
+                    item.meta
                         .neighbor_missing(cx.now, neighbor_addr.expect("non-IP response packet"));
                     break;
                 }
                 (Err(err), _) | (_, Err(err)) => {
                     net_debug!(
                         "{}: cannot dispatch egress packet: {}",
-                        socket.meta().handle,
+                        item.meta.handle,
                         err
                     );
                     return Err(err);
@@ -1216,7 +1212,10 @@ impl<'a> InterfaceInner<'a> {
 
                         // Look for UDP sockets that will accept the UDP packet.
                         // If it does not accept the packet, then send an ICMP message.
-                        for udp_socket in sockets.iter_mut().filter_map(UdpSocket::downcast) {
+                        for udp_socket in sockets
+                            .iter_mut()
+                            .filter_map(|i| UdpSocket::downcast(&mut i.socket))
+                        {
                             if !udp_socket.accepts(&IpRepr::Ipv6(ipv6_repr), &udp_repr) {
                                 continue;
                             }
@@ -1339,7 +1338,10 @@ impl<'a> InterfaceInner<'a> {
         let mut handled_by_raw_socket = false;
 
         // Pass every IP packet to all raw sockets we have registered.
-        for raw_socket in sockets.iter_mut().filter_map(RawSocket::downcast) {
+        for raw_socket in sockets
+            .iter_mut()
+            .filter_map(|i| RawSocket::downcast(&mut i.socket))
+        {
             if !raw_socket.accepts(ip_repr) {
                 continue;
             }
@@ -1471,8 +1473,10 @@ impl<'a> InterfaceInner<'a> {
                 if udp_packet.src_port() == DHCP_SERVER_PORT
                     && udp_packet.dst_port() == DHCP_CLIENT_PORT
                 {
-                    if let Some(dhcp_socket) =
-                        sockets.iter_mut().filter_map(Dhcpv4Socket::downcast).next()
+                    if let Some(dhcp_socket) = sockets
+                        .iter_mut()
+                        .filter_map(|i| Dhcpv4Socket::downcast(&mut i.socket))
+                        .next()
                     {
                         let (src_addr, dst_addr) = (ip_repr.src_addr(), ip_repr.dst_addr());
                         let udp_repr =
@@ -1650,7 +1654,10 @@ impl<'a> InterfaceInner<'a> {
         let mut handled_by_icmp_socket = false;
 
         #[cfg(all(feature = "socket-icmp", feature = "proto-ipv6"))]
-        for icmp_socket in _sockets.iter_mut().filter_map(IcmpSocket::downcast) {
+        for icmp_socket in _sockets
+            .iter_mut()
+            .filter_map(|i| IcmpSocket::downcast(&mut i.socket))
+        {
             if !icmp_socket.accepts(cx, &ip_repr, &icmp_repr.into()) {
                 continue;
             }
@@ -1836,7 +1843,10 @@ impl<'a> InterfaceInner<'a> {
         let mut handled_by_icmp_socket = false;
 
         #[cfg(all(feature = "socket-icmp", feature = "proto-ipv4"))]
-        for icmp_socket in _sockets.iter_mut().filter_map(IcmpSocket::downcast) {
+        for icmp_socket in _sockets
+            .iter_mut()
+            .filter_map(|i| IcmpSocket::downcast(&mut i.socket))
+        {
             if !icmp_socket.accepts(cx, &ip_repr, &icmp_repr.into()) {
                 continue;
             }
@@ -1960,7 +1970,10 @@ impl<'a> InterfaceInner<'a> {
         let udp_repr = UdpRepr::parse(&udp_packet, &src_addr, &dst_addr, &cx.caps.checksum)?;
         let udp_payload = udp_packet.payload();
 
-        for udp_socket in sockets.iter_mut().filter_map(UdpSocket::downcast) {
+        for udp_socket in sockets
+            .iter_mut()
+            .filter_map(|i| UdpSocket::downcast(&mut i.socket))
+        {
             if !udp_socket.accepts(&ip_repr, &udp_repr) {
                 continue;
             }
@@ -2017,7 +2030,10 @@ impl<'a> InterfaceInner<'a> {
         let tcp_packet = TcpPacket::new_checked(ip_payload)?;
         let tcp_repr = TcpRepr::parse(&tcp_packet, &src_addr, &dst_addr, &cx.caps.checksum)?;
 
-        for tcp_socket in sockets.iter_mut().filter_map(TcpSocket::downcast) {
+        for tcp_socket in sockets
+            .iter_mut()
+            .filter_map(|i| TcpSocket::downcast(&mut i.socket))
+        {
             if !tcp_socket.accepts(&ip_repr, &tcp_repr) {
                 continue;
             }

+ 2 - 17
src/socket/dhcpv4.rs

@@ -1,5 +1,4 @@
-use crate::socket::SocketHandle;
-use crate::socket::{Context, SocketMeta};
+use crate::socket::Context;
 use crate::time::{Duration, Instant};
 use crate::wire::dhcpv4::field as dhcpv4_field;
 use crate::wire::HardwareAddress;
@@ -9,7 +8,7 @@ use crate::wire::{
 };
 use crate::{Error, Result};
 
-use super::{PollAt, Socket};
+use super::PollAt;
 
 const DISCOVER_TIMEOUT: Duration = Duration::from_secs(10);
 
@@ -112,7 +111,6 @@ pub enum Event {
 
 #[derive(Debug)]
 pub struct Dhcpv4Socket {
-    pub(crate) meta: SocketMeta,
     /// State of the DHCP client.
     state: ClientState,
     /// Set to true on config/state change, cleared back to false by the `config` function.
@@ -138,7 +136,6 @@ impl Dhcpv4Socket {
     #[allow(clippy::new_without_default)]
     pub fn new() -> Self {
         Dhcpv4Socket {
-            meta: SocketMeta::default(),
             state: ClientState::Discovering(DiscoverState {
                 retry_at: Instant::from_millis(0),
             }),
@@ -520,12 +517,6 @@ impl Dhcpv4Socket {
         }
     }
 
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta.handle
-    }
-
     /// Reset state and restart discovery phase.
     ///
     /// Use this to speed up acquisition of an address in a new
@@ -557,12 +548,6 @@ impl Dhcpv4Socket {
     }
 }
 
-impl<'a> From<Dhcpv4Socket> for Socket<'a> {
-    fn from(val: Dhcpv4Socket) -> Self {
-        Socket::Dhcpv4(val)
-    }
-}
-
 #[cfg(test)]
 mod test {
 

+ 6 - 30
src/socket/icmp.rs

@@ -5,7 +5,7 @@ use core::task::Waker;
 use crate::phy::ChecksumCapabilities;
 #[cfg(feature = "async")]
 use crate::socket::WakerRegistration;
-use crate::socket::{Context, PollAt, Socket, SocketHandle, SocketMeta};
+use crate::socket::{Context, PollAt};
 use crate::storage::{PacketBuffer, PacketMetadata};
 use crate::{Error, Result};
 
@@ -62,7 +62,6 @@ pub type IcmpSocketBuffer<'a> = PacketBuffer<'a, IpAddress>;
 /// [bind]: #method.bind
 #[derive(Debug)]
 pub struct IcmpSocket<'a> {
-    pub(crate) meta: SocketMeta,
     rx_buffer: IcmpSocketBuffer<'a>,
     tx_buffer: IcmpSocketBuffer<'a>,
     /// The endpoint this socket is communicating with
@@ -79,7 +78,6 @@ impl<'a> IcmpSocket<'a> {
     /// Create an ICMP socket with the given buffers.
     pub fn new(rx_buffer: IcmpSocketBuffer<'a>, tx_buffer: IcmpSocketBuffer<'a>) -> IcmpSocket<'a> {
         IcmpSocket {
-            meta: SocketMeta::default(),
             rx_buffer: rx_buffer,
             tx_buffer: tx_buffer,
             endpoint: Endpoint::default(),
@@ -126,12 +124,6 @@ impl<'a> IcmpSocket<'a> {
         self.tx_waker.register(waker)
     }
 
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta.handle
-    }
-
     /// Return the time-to-live (IPv4) or hop limit (IPv6) value used in outgoing packets.
     ///
     /// See also the [set_hop_limit](#method.set_hop_limit) method
@@ -290,12 +282,7 @@ impl<'a> IcmpSocket<'a> {
 
         let packet_buf = self.tx_buffer.enqueue(size, endpoint)?;
 
-        net_trace!(
-            "{}:{}: buffer to send {} octets",
-            self.meta.handle,
-            endpoint,
-            size
-        );
+        net_trace!("icmp:{}: buffer to send {} octets", endpoint, size);
         Ok(packet_buf)
     }
 
@@ -316,8 +303,7 @@ impl<'a> IcmpSocket<'a> {
         let (endpoint, packet_buf) = self.rx_buffer.dequeue()?;
 
         net_trace!(
-            "{}:{}: receive {} buffered octets",
-            self.meta.handle,
+            "icmp:{}: receive {} buffered octets",
             endpoint,
             packet_buf.len()
         );
@@ -417,8 +403,7 @@ impl<'a> IcmpSocket<'a> {
                 );
 
                 net_trace!(
-                    "{}:{}: receiving {} octets",
-                    self.meta.handle,
+                    "icmp:{}: receiving {} octets",
                     icmp_repr.buffer_len(),
                     packet_buf.len()
                 );
@@ -436,8 +421,7 @@ impl<'a> IcmpSocket<'a> {
                 );
 
                 net_trace!(
-                    "{}:{}: receiving {} octets",
-                    self.meta.handle,
+                    "icmp:{}: receiving {} octets",
                     icmp_repr.buffer_len(),
                     packet_buf.len()
                 );
@@ -454,12 +438,10 @@ impl<'a> IcmpSocket<'a> {
     where
         F: FnOnce((IpRepr, IcmpRepr)) -> Result<()>,
     {
-        let handle = self.meta.handle;
         let hop_limit = self.hop_limit.unwrap_or(64);
         self.tx_buffer.dequeue_with(|remote_endpoint, packet_buf| {
             net_trace!(
-                "{}:{}: sending {} octets",
-                handle,
+                "icmp:{}: sending {} octets",
                 remote_endpoint,
                 packet_buf.len()
             );
@@ -515,12 +497,6 @@ impl<'a> IcmpSocket<'a> {
     }
 }
 
-impl<'a> From<IcmpSocket<'a>> for Socket<'a> {
-    fn from(val: IcmpSocket<'a>) -> Self {
-        Socket::Icmp(val)
-    }
-}
-
 #[cfg(test)]
 mod tests_common {
     pub use super::*;

+ 1 - 1
src/socket/meta.rs

@@ -31,7 +31,7 @@ impl Default for NeighborState {
 /// is interested in, but which are more conveniently stored inside the socket itself.
 #[derive(Debug, Default)]
 #[cfg_attr(feature = "defmt", derive(defmt::Format))]
-pub struct Meta {
+pub(crate) struct Meta {
     /// Handle of this socket within its enclosing `SocketSet`.
     /// Mainly useful for debug output.
     pub(crate) handle: SocketHandle,

+ 13 - 36
src/socket/mod.rs

@@ -31,9 +31,7 @@ mod udp;
 #[cfg(feature = "async")]
 mod waker;
 
-pub(crate) use self::meta::Meta as SocketMeta;
 pub use self::set::{Handle as SocketHandle, Item as SocketSetItem, Set as SocketSet};
-pub use self::set::{Iter as SocketSetIter, IterMut as SocketSetIterMut};
 
 #[cfg(feature = "socket-dhcpv4")]
 pub use self::dhcpv4::{Config as Dhcpv4Config, Dhcpv4Socket, Event as Dhcpv4Event};
@@ -85,57 +83,36 @@ pub enum Socket<'a> {
     Dhcpv4(Dhcpv4Socket),
 }
 
-macro_rules! dispatch_socket {
-    ($self_:expr, |$socket:ident| $code:expr) => {
-        dispatch_socket!(@inner $self_, |$socket| $code)
-    };
-    (mut $self_:expr, |$socket:ident| $code:expr) => {
-        dispatch_socket!(@inner mut $self_, |$socket| $code)
-    };
-    (@inner $( $mut_:ident )* $self_:expr, |$socket:ident| $code:expr) => {
-        match $self_ {
+impl<'a> Socket<'a> {
+    pub(crate) fn poll_at(&self, cx: &Context) -> PollAt {
+        match self {
             #[cfg(feature = "socket-raw")]
-            &$( $mut_ )* Socket::Raw(ref $( $mut_ )* $socket) => $code,
+            Socket::Raw(s) => s.poll_at(cx),
             #[cfg(feature = "socket-icmp")]
-            &$( $mut_ )* Socket::Icmp(ref $( $mut_ )* $socket) => $code,
+            Socket::Icmp(s) => s.poll_at(cx),
             #[cfg(feature = "socket-udp")]
-            &$( $mut_ )* Socket::Udp(ref $( $mut_ )* $socket) => $code,
+            Socket::Udp(s) => s.poll_at(cx),
             #[cfg(feature = "socket-tcp")]
-            &$( $mut_ )* Socket::Tcp(ref $( $mut_ )* $socket) => $code,
+            Socket::Tcp(s) => s.poll_at(cx),
             #[cfg(feature = "socket-dhcpv4")]
-            &$( $mut_ )* Socket::Dhcpv4(ref $( $mut_ )* $socket) => $code,
+            Socket::Dhcpv4(s) => s.poll_at(cx),
         }
-    };
-}
-
-impl<'a> Socket<'a> {
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta().handle
-    }
-
-    pub(crate) fn meta(&self) -> &SocketMeta {
-        dispatch_socket!(self, |socket| &socket.meta)
-    }
-
-    pub(crate) fn meta_mut(&mut self) -> &mut SocketMeta {
-        dispatch_socket!(mut self, |socket| &mut socket.meta)
-    }
-
-    pub(crate) fn poll_at(&self, cx: &Context) -> PollAt {
-        dispatch_socket!(self, |socket| socket.poll_at(cx))
     }
 }
 
 /// A conversion trait for network sockets.
 pub trait AnySocket<'a>: Sized {
+    fn upcast(self) -> Socket<'a>;
     fn downcast<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Self>;
 }
 
 macro_rules! from_socket {
     ($socket:ty, $variant:ident) => {
         impl<'a> AnySocket<'a> for $socket {
+            fn upcast(self) -> Socket<'a> {
+                Socket::$variant(self)
+            }
+
             fn downcast<'c>(socket: &'c mut Socket<'a>) -> Option<&'c mut Self> {
                 #[allow(unreachable_patterns)]
                 match socket {

+ 6 - 26
src/socket/raw.rs

@@ -5,7 +5,7 @@ use core::task::Waker;
 use crate::phy::ChecksumCapabilities;
 #[cfg(feature = "async")]
 use crate::socket::WakerRegistration;
-use crate::socket::{Context, PollAt, Socket, SocketHandle, SocketMeta};
+use crate::socket::{Context, PollAt};
 use crate::storage::{PacketBuffer, PacketMetadata};
 use crate::{Error, Result};
 
@@ -27,7 +27,6 @@ pub type RawSocketBuffer<'a> = PacketBuffer<'a, ()>;
 /// transmit and receive packet buffers.
 #[derive(Debug)]
 pub struct RawSocket<'a> {
-    pub(crate) meta: SocketMeta,
     ip_version: IpVersion,
     ip_protocol: IpProtocol,
     rx_buffer: RawSocketBuffer<'a>,
@@ -48,7 +47,6 @@ impl<'a> RawSocket<'a> {
         tx_buffer: RawSocketBuffer<'a>,
     ) -> RawSocket<'a> {
         RawSocket {
-            meta: SocketMeta::default(),
             ip_version,
             ip_protocol,
             rx_buffer,
@@ -95,12 +93,6 @@ impl<'a> RawSocket<'a> {
         self.tx_waker.register(waker)
     }
 
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta.handle
-    }
-
     /// Return the IP version the socket is bound to.
     #[inline]
     pub fn ip_version(&self) -> IpVersion {
@@ -164,8 +156,7 @@ impl<'a> RawSocket<'a> {
         let packet_buf = self.tx_buffer.enqueue(size, ())?;
 
         net_trace!(
-            "{}:{}:{}: buffer to send {} octets",
-            self.meta.handle,
+            "raw:{}:{}: buffer to send {} octets",
             self.ip_version,
             self.ip_protocol,
             packet_buf.len()
@@ -191,8 +182,7 @@ impl<'a> RawSocket<'a> {
         let ((), packet_buf) = self.rx_buffer.dequeue()?;
 
         net_trace!(
-            "{}:{}:{}: receive {} buffered octets",
-            self.meta.handle,
+            "raw:{}:{}: receive {} buffered octets",
             self.ip_version,
             self.ip_protocol,
             packet_buf.len()
@@ -231,8 +221,7 @@ impl<'a> RawSocket<'a> {
         packet_buf[header_len..].copy_from_slice(payload);
 
         net_trace!(
-            "{}:{}:{}: receiving {} octets",
-            self.meta.handle,
+            "raw:{}:{}: receiving {} octets",
             self.ip_version,
             self.ip_protocol,
             packet_buf.len()
@@ -286,15 +275,13 @@ impl<'a> RawSocket<'a> {
             }
         }
 
-        let handle = self.meta.handle;
         let ip_protocol = self.ip_protocol;
         let ip_version = self.ip_version;
         self.tx_buffer.dequeue_with(|&mut (), packet_buf| {
             match prepare(ip_protocol, packet_buf, &cx.caps.checksum) {
                 Ok((ip_repr, raw_packet)) => {
                     net_trace!(
-                        "{}:{}:{}: sending {} octets",
-                        handle,
+                        "raw:{}:{}: sending {} octets",
                         ip_version,
                         ip_protocol,
                         ip_repr.buffer_len() + raw_packet.len()
@@ -303,8 +290,7 @@ impl<'a> RawSocket<'a> {
                 }
                 Err(error) => {
                     net_debug!(
-                        "{}:{}:{}: dropping outgoing packet ({})",
-                        handle,
+                        "raw:{}:{}: dropping outgoing packet ({})",
                         ip_version,
                         ip_protocol,
                         error
@@ -330,12 +316,6 @@ impl<'a> RawSocket<'a> {
     }
 }
 
-impl<'a> From<RawSocket<'a>> for Socket<'a> {
-    fn from(val: RawSocket<'a>) -> Self {
-        Socket::Raw(val)
-    }
-}
-
 #[cfg(test)]
 mod test {
     use super::*;

+ 15 - 60
src/socket/set.rs

@@ -1,15 +1,18 @@
-use core::{fmt, slice};
+use core::fmt;
 use managed::ManagedSlice;
 
 use crate::socket::{AnySocket, Socket};
 
+use super::meta::Meta;
+
 /// An item of a socket set.
 ///
 /// The only reason this struct is public is to allow the socket set storage
 /// to be allocated externally.
 #[derive(Debug)]
 pub struct Item<'a> {
-    socket: Socket<'a>,
+    pub(crate) meta: Meta,
+    pub(crate) socket: Socket<'a>,
 }
 
 /// A handle, identifying a socket in a set.
@@ -45,19 +48,17 @@ impl<'a> Set<'a> {
     ///
     /// # Panics
     /// This function panics if the storage is fixed-size (not a `Vec`) and is full.
-    pub fn add<T>(&mut self, socket: T) -> Handle
-    where
-        T: Into<Socket<'a>>,
-    {
-        fn put<'a>(index: usize, slot: &mut Option<Item<'a>>, mut socket: Socket<'a>) -> Handle {
+    pub fn add<T: AnySocket<'a>>(&mut self, socket: T) -> Handle {
+        fn put<'a>(index: usize, slot: &mut Option<Item<'a>>, socket: Socket<'a>) -> Handle {
             net_trace!("[{}]: adding", index);
             let handle = Handle(index);
-            socket.meta_mut().handle = handle;
-            *slot = Some(Item { socket });
+            let mut meta = Meta::default();
+            meta.handle = handle;
+            *slot = Some(Item { socket, meta });
             handle
         }
 
-        let socket = socket.into();
+        let socket = socket.upcast();
 
         for (index, slot) in self.sockets.iter_mut().enumerate() {
             if slot.is_none() {
@@ -103,58 +104,12 @@ impl<'a> Set<'a> {
     }
 
     /// Iterate every socket in this set.
-    pub fn iter<'d>(&'d self) -> Iter<'d, 'a> {
-        Iter {
-            lower: self.sockets.iter(),
-        }
+    pub fn iter(&self) -> impl Iterator<Item = &Item<'a>> + '_ {
+        self.sockets.iter().filter_map(|x| x.as_ref())
     }
 
     /// Iterate every socket in this set.
-    pub fn iter_mut<'d>(&'d mut self) -> IterMut<'d, 'a> {
-        IterMut {
-            lower: self.sockets.iter_mut(),
-        }
-    }
-}
-
-/// Immutable socket set iterator.
-///
-/// This struct is created by the [iter](struct.SocketSet.html#method.iter)
-/// on [socket sets](struct.SocketSet.html).
-pub struct Iter<'a, 'b: 'a> {
-    lower: slice::Iter<'a, Option<Item<'b>>>,
-}
-
-impl<'a, 'b: 'a> Iterator for Iter<'a, 'b> {
-    type Item = &'a Socket<'b>;
-
-    fn next(&mut self) -> Option<Self::Item> {
-        for item_opt in &mut self.lower {
-            if let Some(item) = item_opt.as_ref() {
-                return Some(&item.socket);
-            }
-        }
-        None
-    }
-}
-
-/// Mutable socket set iterator.
-///
-/// This struct is created by the [iter_mut](struct.SocketSet.html#method.iter_mut)
-/// on [socket sets](struct.SocketSet.html).
-pub struct IterMut<'a, 'b: 'a> {
-    lower: slice::IterMut<'a, Option<Item<'b>>>,
-}
-
-impl<'a, 'b: 'a> Iterator for IterMut<'a, 'b> {
-    type Item = &'a mut Socket<'b>;
-
-    fn next(&mut self) -> Option<Self::Item> {
-        for item_opt in &mut self.lower {
-            if let Some(item) = item_opt.as_mut() {
-                return Some(&mut item.socket);
-            }
-        }
-        None
+    pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>> + '_ {
+        self.sockets.iter_mut().filter_map(|x| x.as_mut())
     }
 }

+ 54 - 118
src/socket/tcp.rs

@@ -8,7 +8,7 @@ use core::{cmp, fmt, mem};
 
 #[cfg(feature = "async")]
 use crate::socket::WakerRegistration;
-use crate::socket::{Context, PollAt, Socket, SocketHandle, SocketMeta};
+use crate::socket::{Context, PollAt};
 use crate::storage::{Assembler, RingBuffer};
 use crate::time::{Duration, Instant};
 use crate::wire::{
@@ -308,7 +308,6 @@ enum AckDelayTimer {
 /// attempts will be reset.
 #[derive(Debug)]
 pub struct TcpSocket<'a> {
-    pub(crate) meta: SocketMeta,
     state: State,
     timer: Timer,
     rtte: RttEstimator,
@@ -411,7 +410,6 @@ impl<'a> TcpSocket<'a> {
         let rx_cap_log2 = mem::size_of::<usize>() * 8 - rx_capacity.leading_zeros() as usize;
 
         TcpSocket {
-            meta: SocketMeta::default(),
             state: State::Closed,
             timer: Timer::new(),
             rtte: RttEstimator::default(),
@@ -486,12 +484,6 @@ impl<'a> TcpSocket<'a> {
         self.tx_waker.register(waker)
     }
 
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta.handle
-    }
-
     /// Return the timeout duration.
     ///
     /// See also the [set_timeout](#method.set_timeout) method.
@@ -948,8 +940,7 @@ impl<'a> TcpSocket<'a> {
         if size > 0 {
             #[cfg(any(test, feature = "verbose"))]
             net_trace!(
-                "{}:{}:{}: tx buffer: enqueueing {} octets (now {})",
-                self.meta.handle,
+                "tcp:{}:{}: tx buffer: enqueueing {} octets (now {})",
                 self.local_endpoint,
                 self.remote_endpoint,
                 size,
@@ -1010,8 +1001,7 @@ impl<'a> TcpSocket<'a> {
         if size > 0 {
             #[cfg(any(test, feature = "verbose"))]
             net_trace!(
-                "{}:{}:{}: rx buffer: dequeueing {} octets (now {})",
-                self.meta.handle,
+                "tcp:{}:{}: rx buffer: dequeueing {} octets (now {})",
                 self.local_endpoint,
                 self.remote_endpoint,
                 size,
@@ -1062,8 +1052,7 @@ impl<'a> TcpSocket<'a> {
         if !buffer.is_empty() {
             #[cfg(any(test, feature = "verbose"))]
             net_trace!(
-                "{}:{}:{}: rx buffer: peeking at {} octets",
-                self.meta.handle,
+                "tcp:{}:{}: rx buffer: peeking at {} octets",
                 self.local_endpoint,
                 self.remote_endpoint,
                 buffer.len()
@@ -1103,16 +1092,14 @@ impl<'a> TcpSocket<'a> {
         if self.state != state {
             if self.remote_endpoint.addr.is_unspecified() {
                 net_trace!(
-                    "{}:{}: state={}=>{}",
-                    self.meta.handle,
+                    "tcp:{}: state={}=>{}",
                     self.local_endpoint,
                     self.state,
                     state
                 );
             } else {
                 net_trace!(
-                    "{}:{}:{}: state={}=>{}",
-                    self.meta.handle,
+                    "tcp:{}:{}: state={}=>{}",
                     self.local_endpoint,
                     self.remote_endpoint,
                     self.state,
@@ -1307,9 +1294,8 @@ impl<'a> TcpSocket<'a> {
             // the initial SYN.
             (State::SynSent, TcpControl::Rst, None) => {
                 net_debug!(
-                    "{}:{}:{}: unacceptable RST (expecting RST|ACK) \
+                    "tcp:{}:{}: unacceptable RST (expecting RST|ACK) \
                             in response to initial SYN",
-                    self.meta.handle,
                     self.local_endpoint,
                     self.remote_endpoint
                 );
@@ -1318,8 +1304,7 @@ impl<'a> TcpSocket<'a> {
             (State::SynSent, TcpControl::Rst, Some(ack_number)) => {
                 if ack_number != self.local_seq_no + 1 {
                     net_debug!(
-                        "{}:{}:{}: unacceptable RST|ACK in response to initial SYN",
-                        self.meta.handle,
+                        "tcp:{}:{}: unacceptable RST|ACK in response to initial SYN",
                         self.local_endpoint,
                         self.remote_endpoint
                     );
@@ -1335,8 +1320,7 @@ impl<'a> TcpSocket<'a> {
             // Every packet after the initial SYN must be an acknowledgement.
             (_, _, None) => {
                 net_debug!(
-                    "{}:{}:{}: expecting an ACK",
-                    self.meta.handle,
+                    "tcp:{}:{}: expecting an ACK",
                     self.local_endpoint,
                     self.remote_endpoint
                 );
@@ -1346,8 +1330,7 @@ impl<'a> TcpSocket<'a> {
             (State::SynSent, TcpControl::Syn, Some(ack_number)) => {
                 if ack_number != self.local_seq_no + 1 {
                     net_debug!(
-                        "{}:{}:{}: unacceptable SYN|ACK in response to initial SYN",
-                        self.meta.handle,
+                        "tcp:{}:{}: unacceptable SYN|ACK in response to initial SYN",
                         self.local_endpoint,
                         self.remote_endpoint
                     );
@@ -1362,18 +1345,16 @@ impl<'a> TcpSocket<'a> {
                 // does it, we do too.
                 if ack_number == self.local_seq_no + 1 {
                     net_debug!(
-                        "{}:{}:{}: expecting a SYN|ACK, received an ACK with the right ack_number, ignoring.",
-                        self.meta.handle,
-                        self.local_endpoint,
+                        "tcp:{}:{}: expecting a SYN|ACK, received an ACK with the right ack_number, ignoring.",
+                                                self.local_endpoint,
                         self.remote_endpoint
                     );
                     return Err(Error::Dropped);
                 }
 
                 net_debug!(
-                    "{}:{}:{}: expecting a SYN|ACK, received an ACK with the wrong ack_number, sending RST.",
-                    self.meta.handle,
-                    self.local_endpoint,
+                    "tcp:{}:{}: expecting a SYN|ACK, received an ACK with the wrong ack_number, sending RST.",
+                                        self.local_endpoint,
                     self.remote_endpoint
                 );
                 return Ok(Some(Self::rst_reply(ip_repr, repr)));
@@ -1381,8 +1362,7 @@ impl<'a> TcpSocket<'a> {
             // Anything else in the SYN-SENT state is invalid.
             (State::SynSent, _, _) => {
                 net_debug!(
-                    "{}:{}:{}: expecting a SYN|ACK",
-                    self.meta.handle,
+                    "tcp:{}:{}: expecting a SYN|ACK",
                     self.local_endpoint,
                     self.remote_endpoint
                 );
@@ -1392,8 +1372,7 @@ impl<'a> TcpSocket<'a> {
             (State::SynReceived, _, Some(ack_number)) => {
                 if ack_number != self.local_seq_no + 1 {
                     net_debug!(
-                        "{}:{}:{}: unacceptable ACK in response to SYN|ACK",
-                        self.meta.handle,
+                        "tcp:{}:{}: unacceptable ACK in response to SYN|ACK",
                         self.local_endpoint,
                         self.remote_endpoint
                     );
@@ -1415,8 +1394,7 @@ impl<'a> TcpSocket<'a> {
 
                 if ack_number < ack_min {
                     net_debug!(
-                        "{}:{}:{}: duplicate ACK ({} not in {}...{})",
-                        self.meta.handle,
+                        "tcp:{}:{}: duplicate ACK ({} not in {}...{})",
                         self.local_endpoint,
                         self.remote_endpoint,
                         ack_number,
@@ -1428,8 +1406,7 @@ impl<'a> TcpSocket<'a> {
 
                 if ack_number > ack_max {
                     net_debug!(
-                        "{}:{}:{}: unacceptable ACK ({} not in {}...{})",
-                        self.meta.handle,
+                        "tcp:{}:{}: unacceptable ACK ({} not in {}...{})",
                         self.local_endpoint,
                         self.remote_endpoint,
                         ack_number,
@@ -1456,9 +1433,8 @@ impl<'a> TcpSocket<'a> {
 
                 if window_start == window_end && segment_start != segment_end {
                     net_debug!(
-                        "{}:{}:{}: non-zero-length segment with zero receive window, \
+                        "tcp:{}:{}: non-zero-length segment with zero receive window, \
                                 will only send an ACK",
-                        self.meta.handle,
                         self.local_endpoint,
                         self.remote_endpoint
                     );
@@ -1467,9 +1443,8 @@ impl<'a> TcpSocket<'a> {
 
                 if segment_start == segment_end && segment_end == window_start - 1 {
                     net_debug!(
-                        "{}:{}:{}: received a keep-alive or window probe packet, \
+                        "tcp:{}:{}: received a keep-alive or window probe packet, \
                                 will send an ACK",
-                        self.meta.handle,
                         self.local_endpoint,
                         self.remote_endpoint
                     );
@@ -1478,9 +1453,8 @@ impl<'a> TcpSocket<'a> {
                     && (window_start <= segment_end && segment_end <= window_end))
                 {
                     net_debug!(
-                        "{}:{}:{}: segment not in receive window \
+                        "tcp:{}:{}: segment not in receive window \
                                 ({}..{} not intersecting {}..{}), will send challenge ACK",
-                        self.meta.handle,
                         self.local_endpoint,
                         self.remote_endpoint,
                         segment_start,
@@ -1526,8 +1500,7 @@ impl<'a> TcpSocket<'a> {
                     if sent_fin && self.tx_buffer.len() + 1 == ack_len {
                         ack_len -= 1;
                         net_trace!(
-                            "{}:{}:{}: received ACK of FIN",
-                            self.meta.handle,
+                            "tcp:{}:{}: received ACK of FIN",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1557,8 +1530,7 @@ impl<'a> TcpSocket<'a> {
             // RSTs in SYN-RECEIVED flip the socket back to the LISTEN state.
             (State::SynReceived, TcpControl::Rst) => {
                 net_trace!(
-                    "{}:{}:{}: received RST",
-                    self.meta.handle,
+                    "tcp:{}:{}: received RST",
                     self.local_endpoint,
                     self.remote_endpoint
                 );
@@ -1571,8 +1543,7 @@ impl<'a> TcpSocket<'a> {
             // RSTs in any other state close the socket.
             (_, TcpControl::Rst) => {
                 net_trace!(
-                    "{}:{}:{}: received RST",
-                    self.meta.handle,
+                    "tcp:{}:{}: received RST",
                     self.local_endpoint,
                     self.remote_endpoint
                 );
@@ -1584,12 +1555,11 @@ impl<'a> TcpSocket<'a> {
 
             // SYN packets in the LISTEN state change it to SYN-RECEIVED.
             (State::Listen, TcpControl::Syn) => {
-                net_trace!("{}:{}: received SYN", self.meta.handle, self.local_endpoint);
+                net_trace!("tcp:{}: received SYN", self.local_endpoint);
                 if let Some(max_seg_size) = repr.max_seg_size {
                     if max_seg_size == 0 {
                         net_trace!(
-                            "{}:{}:{}: received SYNACK with zero MSS, ignoring",
-                            self.meta.handle,
+                            "tcp:{}:{}: received SYNACK with zero MSS, ignoring",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1632,16 +1602,14 @@ impl<'a> TcpSocket<'a> {
             // SYN|ACK packets in the SYN-SENT state change it to ESTABLISHED.
             (State::SynSent, TcpControl::Syn) => {
                 net_trace!(
-                    "{}:{}:{}: received SYN|ACK",
-                    self.meta.handle,
+                    "tcp:{}:{}: received SYN|ACK",
                     self.local_endpoint,
                     self.remote_endpoint
                 );
                 if let Some(max_seg_size) = repr.max_seg_size {
                     if max_seg_size == 0 {
                         net_trace!(
-                            "{}:{}:{}: received SYNACK with zero MSS, ignoring",
-                            self.meta.handle,
+                            "tcp:{}:{}: received SYNACK with zero MSS, ignoring",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1745,8 +1713,7 @@ impl<'a> TcpSocket<'a> {
 
             _ => {
                 net_debug!(
-                    "{}:{}:{}: unexpected packet {}",
-                    self.meta.handle,
+                    "tcp:{}:{}: unexpected packet {}",
                     self.local_endpoint,
                     self.remote_endpoint,
                     repr
@@ -1770,8 +1737,7 @@ impl<'a> TcpSocket<'a> {
             // Dequeue acknowledged octets.
             debug_assert!(self.tx_buffer.len() >= ack_len);
             net_trace!(
-                "{}:{}:{}: tx buffer: dequeueing {} octets (now {})",
-                self.meta.handle,
+                "tcp:{}:{}: tx buffer: dequeueing {} octets (now {})",
                 self.local_endpoint,
                 self.remote_endpoint,
                 ack_len,
@@ -1805,8 +1771,7 @@ impl<'a> TcpSocket<'a> {
                     self.local_rx_dup_acks = self.local_rx_dup_acks.saturating_add(1);
 
                     net_debug!(
-                        "{}:{}:{}: received duplicate ACK for seq {} (duplicate nr {}{})",
-                        self.meta.handle,
+                        "tcp:{}:{}: received duplicate ACK for seq {} (duplicate nr {}{})",
                         self.local_endpoint,
                         self.remote_endpoint,
                         ack_number,
@@ -1821,8 +1786,7 @@ impl<'a> TcpSocket<'a> {
                     if self.local_rx_dup_acks == 3 {
                         self.timer.set_for_fast_retransmit();
                         net_debug!(
-                            "{}:{}:{}: started fast retransmit",
-                            self.meta.handle,
+                            "tcp:{}:{}: started fast retransmit",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1833,8 +1797,7 @@ impl<'a> TcpSocket<'a> {
                     if self.local_rx_dup_acks > 0 {
                         self.local_rx_dup_acks = 0;
                         net_debug!(
-                            "{}:{}:{}: reset duplicate ACK count",
-                            self.meta.handle,
+                            "tcp:{}:{}: reset duplicate ACK count",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1868,8 +1831,7 @@ impl<'a> TcpSocket<'a> {
                 debug_assert!(self.assembler.total_size() == self.rx_buffer.capacity());
                 // Place payload octets into the buffer.
                 net_trace!(
-                    "{}:{}:{}: rx buffer: receiving {} octets at offset {}",
-                    self.meta.handle,
+                    "tcp:{}:{}: rx buffer: receiving {} octets at offset {}",
                     self.local_endpoint,
                     self.remote_endpoint,
                     payload_len,
@@ -1882,8 +1844,7 @@ impl<'a> TcpSocket<'a> {
             }
             Err(_) => {
                 net_debug!(
-                    "{}:{}:{}: assembler: too many holes to add {} octets at offset {}",
-                    self.meta.handle,
+                    "tcp:{}:{}: assembler: too many holes to add {} octets at offset {}",
                     self.local_endpoint,
                     self.remote_endpoint,
                     payload_len,
@@ -1897,8 +1858,7 @@ impl<'a> TcpSocket<'a> {
             debug_assert!(self.assembler.total_size() == self.rx_buffer.capacity());
             // Enqueue the contiguous data octets in front of the buffer.
             net_trace!(
-                "{}:{}:{}: rx buffer: enqueueing {} octets (now {})",
-                self.meta.handle,
+                "tcp:{}:{}: rx buffer: enqueueing {} octets (now {})",
                 self.local_endpoint,
                 self.remote_endpoint,
                 contig_len,
@@ -1914,8 +1874,7 @@ impl<'a> TcpSocket<'a> {
         if !self.assembler.is_empty() {
             // Print the ranges recorded in the assembler.
             net_trace!(
-                "{}:{}:{}: assembler: {}",
-                self.meta.handle,
+                "tcp:{}:{}: assembler: {}",
                 self.local_endpoint,
                 self.remote_endpoint,
                 self.assembler
@@ -1928,8 +1887,7 @@ impl<'a> TcpSocket<'a> {
                 self.ack_delay_timer = match self.ack_delay_timer {
                     AckDelayTimer::Idle => {
                         net_trace!(
-                            "{}:{}:{}: starting delayed ack timer",
-                            self.meta.handle,
+                            "tcp:{}:{}: starting delayed ack timer",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1941,8 +1899,7 @@ impl<'a> TcpSocket<'a> {
                     // For now, we send an ACK every second received packet, full-sized or not.
                     AckDelayTimer::Waiting(_) => {
                         net_trace!(
-                            "{}:{}:{}: delayed ack timer already started, forcing expiry",
-                            self.meta.handle,
+                            "tcp:{}:{}: delayed ack timer already started, forcing expiry",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1950,8 +1907,7 @@ impl<'a> TcpSocket<'a> {
                     }
                     AckDelayTimer::Immediate => {
                         net_trace!(
-                            "{}:{}:{}: delayed ack timer already force-expired",
-                            self.meta.handle,
+                            "tcp:{}:{}: delayed ack timer already force-expired",
                             self.local_endpoint,
                             self.remote_endpoint
                         );
@@ -1969,8 +1925,7 @@ impl<'a> TcpSocket<'a> {
             // This is fine because smoltcp assumes that it can always transmit zero or one
             // packets for every packet it receives.
             net_trace!(
-                "{}:{}:{}: ACKing incoming segment",
-                self.meta.handle,
+                "tcp:{}:{}: ACKing incoming segment",
                 self.local_endpoint,
                 self.remote_endpoint
             );
@@ -2097,8 +2052,7 @@ impl<'a> TcpSocket<'a> {
         if self.timed_out(cx.now) {
             // If a timeout expires, we should abort the connection.
             net_debug!(
-                "{}:{}:{}: timeout exceeded",
-                self.meta.handle,
+                "tcp:{}:{}: timeout exceeded",
                 self.local_endpoint,
                 self.remote_endpoint
             );
@@ -2107,8 +2061,7 @@ impl<'a> TcpSocket<'a> {
             if let Some(retransmit_delta) = self.timer.should_retransmit(cx.now) {
                 // If a retransmit timer expired, we should resend data starting at the last ACK.
                 net_debug!(
-                    "{}:{}:{}: retransmitting at t+{}",
-                    self.meta.handle,
+                    "tcp:{}:{}: retransmitting at t+{}",
                     self.local_endpoint,
                     self.remote_endpoint,
                     retransmit_delta
@@ -2134,48 +2087,42 @@ impl<'a> TcpSocket<'a> {
         if self.seq_to_transmit(cx) {
             // If we have data to transmit and it fits into partner's window, do it.
             net_trace!(
-                "{}:{}:{}: outgoing segment will send data or flags",
-                self.meta.handle,
+                "tcp:{}:{}: outgoing segment will send data or flags",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if self.ack_to_transmit() && self.delayed_ack_expired(cx.now) {
             // If we have data to acknowledge, do it.
             net_trace!(
-                "{}:{}:{}: outgoing segment will acknowledge",
-                self.meta.handle,
+                "tcp:{}:{}: outgoing segment will acknowledge",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if self.window_to_update() && self.delayed_ack_expired(cx.now) {
             // If we have window length increase to advertise, do it.
             net_trace!(
-                "{}:{}:{}: outgoing segment will update window",
-                self.meta.handle,
+                "tcp:{}:{}: outgoing segment will update window",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if self.state == State::Closed {
             // If we need to abort the connection, do it.
             net_trace!(
-                "{}:{}:{}: outgoing segment will abort connection",
-                self.meta.handle,
+                "tcp:{}:{}: outgoing segment will abort connection",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if self.timer.should_keep_alive(cx.now) {
             // If we need to transmit a keep-alive packet, do it.
             net_trace!(
-                "{}:{}:{}: keep-alive timer expired",
-                self.meta.handle,
+                "tcp:{}:{}: keep-alive timer expired",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if self.timer.should_close(cx.now) {
             // If we have spent enough time in the TIME-WAIT state, close the socket.
             net_trace!(
-                "{}:{}:{}: TIME-WAIT timer expired",
-                self.meta.handle,
+                "tcp:{}:{}: TIME-WAIT timer expired",
                 self.local_endpoint,
                 self.remote_endpoint
             );
@@ -2309,15 +2256,13 @@ impl<'a> TcpSocket<'a> {
         // Trace a summary of what will be sent.
         if is_keep_alive {
             net_trace!(
-                "{}:{}:{}: sending a keep-alive",
-                self.meta.handle,
+                "tcp:{}:{}: sending a keep-alive",
                 self.local_endpoint,
                 self.remote_endpoint
             );
         } else if !repr.payload.is_empty() {
             net_trace!(
-                "{}:{}:{}: tx buffer: sending {} octets at offset {}",
-                self.meta.handle,
+                "tcp:{}:{}: tx buffer: sending {} octets at offset {}",
                 self.local_endpoint,
                 self.remote_endpoint,
                 repr.payload.len(),
@@ -2335,8 +2280,7 @@ impl<'a> TcpSocket<'a> {
                 _ => "<unreachable>",
             };
             net_trace!(
-                "{}:{}:{}: sending {}",
-                self.meta.handle,
+                "tcp:{}:{}: sending {}",
                 self.local_endpoint,
                 self.remote_endpoint,
                 flags
@@ -2368,16 +2312,14 @@ impl<'a> TcpSocket<'a> {
             AckDelayTimer::Idle => {}
             AckDelayTimer::Waiting(_) => {
                 net_trace!(
-                    "{}:{}:{}: stop delayed ack timer",
-                    self.meta.handle,
+                    "tcp:{}:{}: stop delayed ack timer",
                     self.local_endpoint,
                     self.remote_endpoint
                 )
             }
             AckDelayTimer::Immediate => {
                 net_trace!(
-                    "{}:{}:{}: stop delayed ack timer (was force-expired)",
-                    self.meta.handle,
+                    "tcp:{}:{}: stop delayed ack timer (was force-expired)",
                     self.local_endpoint,
                     self.remote_endpoint
                 )
@@ -2459,12 +2401,6 @@ impl<'a> TcpSocket<'a> {
     }
 }
 
-impl<'a> From<TcpSocket<'a>> for Socket<'a> {
-    fn from(val: TcpSocket<'a>) -> Self {
-        Socket::Tcp(val)
-    }
-}
-
 impl<'a> fmt::Write for TcpSocket<'a> {
     fn write_str(&mut self, slice: &str) -> fmt::Result {
         let slice = slice.as_bytes();

+ 6 - 27
src/socket/udp.rs

@@ -4,7 +4,7 @@ use core::task::Waker;
 
 #[cfg(feature = "async")]
 use crate::socket::WakerRegistration;
-use crate::socket::{Context, PollAt, Socket, SocketHandle, SocketMeta};
+use crate::socket::{Context, PollAt};
 use crate::storage::{PacketBuffer, PacketMetadata};
 use crate::wire::{IpEndpoint, IpProtocol, IpRepr, UdpRepr};
 use crate::{Error, Result};
@@ -21,7 +21,6 @@ pub type UdpSocketBuffer<'a> = PacketBuffer<'a, IpEndpoint>;
 /// packet buffers.
 #[derive(Debug)]
 pub struct UdpSocket<'a> {
-    pub(crate) meta: SocketMeta,
     endpoint: IpEndpoint,
     rx_buffer: UdpSocketBuffer<'a>,
     tx_buffer: UdpSocketBuffer<'a>,
@@ -37,7 +36,6 @@ impl<'a> UdpSocket<'a> {
     /// Create an UDP socket with the given buffers.
     pub fn new(rx_buffer: UdpSocketBuffer<'a>, tx_buffer: UdpSocketBuffer<'a>) -> UdpSocket<'a> {
         UdpSocket {
-            meta: SocketMeta::default(),
             endpoint: IpEndpoint::default(),
             rx_buffer: rx_buffer,
             tx_buffer: tx_buffer,
@@ -84,12 +82,6 @@ impl<'a> UdpSocket<'a> {
         self.tx_waker.register(waker)
     }
 
-    /// Return the socket handle.
-    #[inline]
-    pub fn handle(&self) -> SocketHandle {
-        self.meta.handle
-    }
-
     /// Return the bound endpoint.
     #[inline]
     pub fn endpoint(&self) -> IpEndpoint {
@@ -225,8 +217,7 @@ impl<'a> UdpSocket<'a> {
         let payload_buf = self.tx_buffer.enqueue(size, endpoint)?;
 
         net_trace!(
-            "{}:{}:{}: buffer to send {} octets",
-            self.meta.handle,
+            "udp:{}:{}: buffer to send {} octets",
             self.endpoint,
             endpoint,
             size
@@ -250,8 +241,7 @@ impl<'a> UdpSocket<'a> {
         let (endpoint, payload_buf) = self.rx_buffer.dequeue()?;
 
         net_trace!(
-            "{}:{}:{}: receive {} buffered octets",
-            self.meta.handle,
+            "udp:{}:{}: receive {} buffered octets",
             self.endpoint,
             endpoint,
             payload_buf.len()
@@ -276,12 +266,10 @@ impl<'a> UdpSocket<'a> {
     ///
     /// It returns `Err(Error::Exhausted)` if the receive buffer is empty.
     pub fn peek(&mut self) -> Result<(&[u8], &IpEndpoint)> {
-        let handle = self.meta.handle;
         let endpoint = self.endpoint;
         self.rx_buffer.peek().map(|(remote_endpoint, payload_buf)| {
             net_trace!(
-                "{}:{}:{}: peek {} buffered octets",
-                handle,
+                "udp:{}:{}: peek {} buffered octets",
                 endpoint,
                 remote_endpoint,
                 payload_buf.len()
@@ -338,8 +326,7 @@ impl<'a> UdpSocket<'a> {
             .copy_from_slice(payload);
 
         net_trace!(
-            "{}:{}:{}: receiving {} octets",
-            self.meta.handle,
+            "udp:{}:{}: receiving {} octets",
             self.endpoint,
             endpoint,
             size
@@ -355,15 +342,13 @@ impl<'a> UdpSocket<'a> {
     where
         F: FnOnce((IpRepr, UdpRepr, &[u8])) -> Result<()>,
     {
-        let handle = self.handle();
         let endpoint = self.endpoint;
         let hop_limit = self.hop_limit.unwrap_or(64);
 
         self.tx_buffer
             .dequeue_with(|remote_endpoint, payload_buf| {
                 net_trace!(
-                    "{}:{}:{}: sending {} octets",
-                    handle,
+                    "udp:{}:{}: sending {} octets",
                     endpoint,
                     endpoint,
                     payload_buf.len()
@@ -398,12 +383,6 @@ impl<'a> UdpSocket<'a> {
     }
 }
 
-impl<'a> From<UdpSocket<'a>> for Socket<'a> {
-    fn from(val: UdpSocket<'a>) -> Self {
-        Socket::Udp(val)
-    }
-}
-
 #[cfg(test)]
 mod test {
     use super::*;