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

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

commit 9ce35caf4e2e187d27e1fe0ce884dc7901b28739
Author: zhanghongyu <[email protected]>
AuthorDate: Mon Jul 14 11:10:33 2025 +0800

    net/tcp: fix the problem of nested tx in the rxcb process
    
    since the current txnotify is executed synchronously at the location of
    the current call without switching threads, resources such as d_iob need
    to be cached first.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 net/tcp/tcp_send_buffered.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c
index 3ad02a6d5f2..0be1cac5e6b 100644
--- a/net/tcp/tcp_send_buffered.c
+++ b/net/tcp/tcp_send_buffered.c
@@ -602,6 +602,18 @@ static uint16_t psock_send_eventhandler(FAR struct 
net_driver_s *dev,
 
                   if ((flags & TCP_NEWDATA) != 0)
                     {
+                      FAR uint8_t *buf = dev->d_buf;
+                      FAR uint8_t *appdata = dev->d_appdata;
+                      uint16_t len = dev->d_len;
+#ifdef CONFIG_NET_TCPURGDATA
+                      FAR uint8_t *urgdata = dev->d_urgdata;
+                      uint16_t urglen = dev->d_urglen;
+#endif
+                      FAR struct iob_s *iob = dev->d_iob;
+
+                      dev->d_buf = NULL;
+                      dev->d_iob = NULL;
+
                       /* The current receive data needs to be handled by
                        * following tcp_recvhandler or tcp_data_event. Notify
                        * driver to send the message and marked as rexmit
@@ -609,7 +621,16 @@ static uint16_t psock_send_eventhandler(FAR struct 
net_driver_s *dev,
 
                       TCP_WBNACK(wrb) = 0;
                       conn->timeout = true;
+
                       netdev_txnotify_dev(conn->dev);
+                      netdev_iob_replace(dev, iob);
+                      dev->d_buf = buf;
+                      dev->d_appdata = appdata;
+                      dev->d_len = len;
+#ifdef CONFIG_NET_TCPURGDATA
+                      dev->d_urgdata = urgdata;
+                      dev->d_urglen = urglen;
+#endif
                       return flags;
                     }
 

Reply via email to