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

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

commit cf9eb8d6b98453547d5249b146b13bfeb54c8933
Author: raiden00pl <[email protected]>
AuthorDate: Tue Nov 17 20:38:26 2026 +0100

    net/tcp: pass a new ACK to the application before dropping a segment.
    
    An old or out-of-order segment can acknowledge new data.  tcp_input()
    accounts the ACK, but only replies with an ACK and drops TCP_ACKDATA,
    so an unbuffered send() waits forever for data that was acknowledged.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 net/tcp/tcp_input.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c
index 6a3284f670c..702f0a6cbc1 100644
--- a/net/tcp/tcp_input.c
+++ b/net/tcp/tcp_input.c
@@ -670,6 +670,35 @@ static void tcp_clear_zero_probe(FAR struct tcp_conn_s 
*conn,
     }
 }
 
+/****************************************************************************
+ * Name: tcp_input_dropack
+ *
+ * Description:
+ *   Drop the data of a segment.  A new ACK in the segment is passed to the
+ *   application first, as the ACK has already been accounted.
+ *
+ * Assumptions:
+ *   The network is locked.
+ *
+ ****************************************************************************/
+
+static void tcp_input_dropack(FAR struct net_driver_s *dev,
+                              FAR struct tcp_conn_s *conn,
+                              uint32_t flags, uint16_t tcpiplen)
+{
+  if ((flags & TCP_ACKDATA) != 0)
+    {
+      dev->d_len    = 0;
+      dev->d_sndlen = 0;
+      tcp_appsend(dev, conn, tcp_callback(dev, conn, TCP_ACKDATA) |
+                             TCP_SNDACK);
+    }
+  else
+    {
+      tcp_send(dev, conn, TCP_ACK, tcpiplen);
+    }
+}
+
 /****************************************************************************
  * Name: tcp_input
  *
@@ -1403,7 +1432,7 @@ skip_rtt:
                    * E.g. a keep-alive segment.
                    */
 
-                  tcp_send(dev, conn, TCP_ACK, tcpiplen);
+                  tcp_input_dropack(dev, conn, flags, tcpiplen);
                   return;
                 }
             }
@@ -1414,7 +1443,7 @@ skip_rtt:
 
               tcp_input_ofosegs(dev, conn, iplen);
 #endif
-              tcp_send(dev, conn, TCP_ACK, tcpiplen);
+              tcp_input_dropack(dev, conn, flags, tcpiplen);
               return;
             }
         }

Reply via email to