You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/18 16:13:43 UTC

[incubator-nuttx] branch master updated: net/tcp/sendfile: swapped the location of TCP_DISCONN_EVENTS and TCP_ACKDATA conditions towards tcp_send_unbuffered.c unification

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/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 79e609a  net/tcp/sendfile: swapped the location of TCP_DISCONN_EVENTS and TCP_ACKDATA conditions towards tcp_send_unbuffered.c unification
79e609a is described below

commit 79e609a8c827959d616a8c4922a48b9081dc62c5
Author: Alexander Lunev <al...@mail.ru>
AuthorDate: Tue Jan 18 17:14:21 2022 +0300

    net/tcp/sendfile: swapped the location of TCP_DISCONN_EVENTS and TCP_ACKDATA conditions towards tcp_send_unbuffered.c unification
---
 net/tcp/tcp_send_unbuffered.c | 12 +++++++--
 net/tcp/tcp_sendfile.c        | 60 ++++++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c
index 4fc690f..000a2a3 100644
--- a/net/tcp/tcp_send_unbuffered.c
+++ b/net/tcp/tcp_send_unbuffered.c
@@ -209,6 +209,8 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
 
   /* If this packet contains an acknowledgement, then update the count of
    * acknowledged bytes.
+   * This condition is located here for performance reasons
+   * (TCP_ACKDATA is the most frequent event).
    */
 
   if ((flags & TCP_ACKDATA) != 0)
@@ -291,7 +293,10 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
       pstate->snd_prev_wnd = conn->snd_wnd;
     }
 
-  /* Check if we are being asked to retransmit data */
+  /* Check if we are being asked to retransmit data.
+   * This condition is located here after TCP_ACKDATA for performance reasons
+   * (TCP_REXMIT is less frequent than TCP_ACKDATA).
+   */
 
   if ((flags & TCP_REXMIT) != 0)
     {
@@ -332,7 +337,10 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
       return flags;
     }
 
-  /* Check for a loss of connection */
+  /* Check for a loss of connection.
+   * This condition is located here after both the TCP_ACKDATA and TCP_REXMIT
+   * because TCP_DISCONN_EVENTS is the least frequent event.
+   */
 
   else if ((flags & TCP_DISCONN_EVENTS) != 0)
     {
diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c
index 745a489..f2e21ce 100644
--- a/net/tcp/tcp_sendfile.c
+++ b/net/tcp/tcp_sendfile.c
@@ -199,35 +199,13 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
   ninfo("flags: %04x acked: %" PRId32 " sent: %zd\n",
         flags, pstate->snd_acked, pstate->snd_sent);
 
-  /* Check for a loss of connection */
-
-  if ((flags & TCP_DISCONN_EVENTS) != 0)
-    {
-      nwarn("WARNING: Lost connection\n");
-
-      /* We could get here recursively through the callback actions of
-       * tcp_lost_connection().  So don't repeat that action if we have
-       * already been disconnected.
-       */
-
-      if (_SS_ISCONNECTED(psock->s_flags))
-        {
-          /* Report not connected */
-
-          tcp_lost_connection(psock, pstate->snd_cb, flags);
-        }
-
-      /* Report not connected */
-
-      pstate->snd_sent = -ENOTCONN;
-      goto end_wait;
-    }
-
   /* If this packet contains an acknowledgement, then update the count of
    * acknowledged bytes.
+   * This condition is located here for performance reasons
+   * (TCP_ACKDATA is the most frequent event).
    */
 
-  else if ((flags & TCP_ACKDATA) != 0)
+  if ((flags & TCP_ACKDATA) != 0)
     {
       FAR struct tcp_hdr_s *tcp;
 
@@ -278,7 +256,10 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
       /* No. Fall through to send more data if necessary */
     }
 
-  /* Check if we are being asked to retransmit data */
+  /* Check if we are being asked to retransmit data.
+   * This condition is located here after TCP_ACKDATA for performance reasons
+   * (TCP_REXMIT is less frequent than TCP_ACKDATA).
+   */
 
   else if ((flags & TCP_REXMIT) != 0)
     {
@@ -294,6 +275,33 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
 #endif
     }
 
+  /* Check for a loss of connection.
+   * This condition is located here after both the TCP_ACKDATA and TCP_REXMIT
+   * because TCP_DISCONN_EVENTS is the least frequent event.
+   */
+
+  else if ((flags & TCP_DISCONN_EVENTS) != 0)
+    {
+      nwarn("WARNING: Lost connection\n");
+
+      /* We could get here recursively through the callback actions of
+       * tcp_lost_connection().  So don't repeat that action if we have
+       * already been disconnected.
+       */
+
+      if (_SS_ISCONNECTED(psock->s_flags))
+        {
+          /* Report not connected */
+
+          tcp_lost_connection(psock, pstate->snd_cb, flags);
+        }
+
+      /* Report not connected */
+
+      pstate->snd_sent = -ENOTCONN;
+      goto end_wait;
+    }
+
   /* We get here if (1) not all of the data has been ACKed, (2) we have been
    * asked to retransmit data, (3) the connection is still healthy, and (4)
    * the outgoing packet is available for our use.  In this case, we are