This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 5f4c9d38b329359304f0bb13a95a06a4bb98a5b5
Author: wenquan1 <[email protected]>
AuthorDate: Thu Apr 2 09:27:55 2026 +0800

    net: move errahead from pkt_conn_s to socket_conn_s.
    
    Move the error-ahead queue (errahead) from pkt_conn_s to the common
    socket_conn_s as s_errahead. This allows other protocol stacks (e.g.
    UDP) to reuse the same error queue for TX timestamping support.
    
    Signed-off-by: wenquan1 <[email protected]>
---
 include/nuttx/net/net.h | 4 ++++
 net/pkt/pkt.h           | 4 ----
 net/pkt/pkt_conn.c      | 8 --------
 net/pkt/pkt_input.c     | 2 +-
 net/pkt/pkt_netpoll.c   | 4 ++--
 net/pkt/pkt_recvmsg.c   | 5 +++--
 net/utils/utils.h       | 6 ++++++
 7 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index aecf69550d0..f0a71f0c1bd 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -257,6 +257,10 @@ struct socket_conn_s
   uint8_t       s_ttl;       /* Default time-to-live */
 #endif
 
+#ifdef CONFIG_NET_TIMESTAMP
+  struct iob_queue_s s_errahead; /* TX timestamp error queue */
+#endif
+
   /* Connection-specific content may follow */
 };
 
diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h
index c09670dd01a..274bae393ea 100644
--- a/net/pkt/pkt.h
+++ b/net/pkt/pkt.h
@@ -107,10 +107,6 @@ struct pkt_conn_s
 
   struct iob_queue_s readahead;   /* Read-ahead buffering */
 
-#ifdef CONFIG_NET_TIMESTAMP
-  struct iob_queue_s errahead;    /* Error-ahead buffering */
-#endif
-
   FAR struct iob_s  *pendiob;     /* The iob currently being sent */
 
   /* The following is a list of poll structures of threads waiting for
diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c
index 0e18976704b..3d97e155b32 100644
--- a/net/pkt/pkt_conn.c
+++ b/net/pkt/pkt_conn.c
@@ -154,20 +154,12 @@ void pkt_free(FAR struct pkt_conn_s *conn)
 
   iob_free_queue(&conn->readahead);
 
-#ifdef CONFIG_NET_TIMESTAMP
-  iob_free_queue(&conn->errahead);
-#endif
-
   /* Free the read-ahead data.  pkt_in_() queues frames with the list
    * locked, so no new frame can come in after dq_rem().
    */
 
   iob_free_queue(&conn->readahead);
 
-#ifdef CONFIG_NET_TIMESTAMP
-  iob_free_queue(&conn->errahead);
-#endif
-
 #ifdef CONFIG_NET_PKT_WRITE_BUFFERS
   /* Free the write queue */
 
diff --git a/net/pkt/pkt_input.c b/net/pkt/pkt_input.c
index 87d61249c00..fab172f6510 100644
--- a/net/pkt/pkt_input.c
+++ b/net/pkt/pkt_input.c
@@ -169,7 +169,7 @@ static int pkt_in_(FAR struct net_driver_s *dev, bool 
loopback)
 
       if (dev->d_iob->io_conn == &conn->sconn)
         {
-          if (pkt_datahandler(dev, conn, &conn->errahead) > 0)
+          if (pkt_datahandler(dev, conn, &conn->sconn.s_errahead) > 0)
             {
               pkt_callback(dev, conn, PKT_NEWDATA);
             }
diff --git a/net/pkt/pkt_netpoll.c b/net/pkt/pkt_netpoll.c
index ebd682fa529..5f18aca9331 100644
--- a/net/pkt/pkt_netpoll.c
+++ b/net/pkt/pkt_netpoll.c
@@ -138,7 +138,7 @@ static uint32_t pkt_poll_eventhandler(FAR struct 
net_driver_s *dev,
 #ifdef CONFIG_NET_TIMESTAMP
       /* Check for timestamping data */
 
-      if (!IOB_QEMPTY(&info->conn->errahead))
+      if (!IOB_QEMPTY(&info->conn->sconn.s_errahead))
         {
           eventset |= POLLPRI | POLLERR;
         }
@@ -281,7 +281,7 @@ int pkt_pollsetup(FAR struct socket *psock, FAR struct 
pollfd_s *fds)
   /* Check for timestamping data */
 
 #ifdef CONFIG_NET_TIMESTAMP
-  if (!IOB_QEMPTY(&conn->errahead))
+  if (!IOB_QEMPTY(&conn->sconn.s_errahead))
     {
       eventset |= POLLPRI | POLLERR;
     }
diff --git a/net/pkt/pkt_recvmsg.c b/net/pkt/pkt_recvmsg.c
index 600796a256f..c4660b8ad29 100644
--- a/net/pkt/pkt_recvmsg.c
+++ b/net/pkt/pkt_recvmsg.c
@@ -589,9 +589,10 @@ ssize_t pkt_recvmsg(FAR struct socket *psock, FAR struct 
msghdr *msg,
 #ifdef CONFIG_NET_TIMESTAMP
   if (flags & MSG_ERRQUEUE)
     {
-      if (!IOB_QEMPTY(&conn->errahead))
+      if (!IOB_QEMPTY(&conn->sconn.s_errahead))
         {
-          ret = pkt_readdata(&state, &conn->errahead, append_timestamping);
+          ret = pkt_readdata(&state, &conn->sconn.s_errahead,
+                             append_timestamping);
         }
       else
         {
diff --git a/net/utils/utils.h b/net/utils/utils.h
index bec54cfd562..0ed741b2930 100644
--- a/net/utils/utils.h
+++ b/net/utils/utils.h
@@ -192,6 +192,12 @@ static inline_function void conn_uninit(FAR struct 
socket_conn_s *sconn)
 {
   DEBUGASSERT(sconn != NULL);
 
+#ifdef CONFIG_NET_TIMESTAMP
+  /* Release any error-ahead buffers attached to the connection */
+
+  iob_free_queue(&sconn->s_errahead);
+#endif
+
   /* Destroy the connection lock */
 
   nxrmutex_destroy(&sconn->s_lock);

Reply via email to