You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/16 17:56:07 UTC

[GitHub] [nuttx] xiaoxiang781216 commented on a diff in pull request #8129: net/tcp: correct behavior of SO_LINGER

xiaoxiang781216 commented on code in PR #8129:
URL: https://github.com/apache/nuttx/pull/8129#discussion_r1071482235


##########
net/tcp/tcp_timer.c:
##########
@@ -352,6 +352,31 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
       return;
     }
 
+#ifdef CONFIG_NET_SOLINGER
+  /* Send reset immediately if linger timeout */
+
+  if (_SO_GETOPT(conn->sconn.s_options, SO_LINGER) &&
+      conn->ltimeout != 0 && conn->ltimeout <= clock_systime_ticks())

Review Comment:
   (socktimeo_t)(conn->ltimeout - clock_systime_ticks()) <= 0



##########
net/tcp/tcp_timer.c:
##########
@@ -702,6 +727,29 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
   dev->d_len = 0;
 
 done:
+#ifdef CONFIG_NET_SOLINGER
+  /* Re-update tcp timeout */
+
+  if (_SO_GETOPT(conn->sconn.s_options, SO_LINGER) &&

Review Comment:
   move into tcp_update_timer



##########
net/tcp/tcp.h:
##########
@@ -233,7 +233,9 @@ struct tcp_conn_s
   uint16_t tx_unacked;    /* Number bytes sent but not yet ACKed */
 #endif
   uint16_t flags;         /* Flags of TCP-specific options */
-
+#ifdef CONFIG_NET_SOLINGER
+  sclock_t ltimeout;      /* Linger timeout expiration */

Review Comment:
   Let's reuse s_linger as the absolute timeout?



##########
net/tcp/tcp_close.c:
##########
@@ -318,6 +289,35 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
       conn->clscb->event = tcp_close_eventhandler;
       conn->clscb->priv  = conn; /* reference for event handler to free cb */
 
+#ifdef CONFIG_NET_SOLINGER
+      /* SO_LINGER
+       *   Lingers on a close() if data is present. This option controls the
+       *   action taken when unsent messages queue on a socket and close() is
+       *   performed. If SO_LINGER is set, the system shall block the calling
+       *   thread during close() until it can transmit the data or until the
+       *   time expires. If SO_LINGER is not specified, and close() is
+       *   issued, the system handles the call in a way that allows the
+       *   calling thread to continue as quickly as possible. This option
+       *   takes a linger structure, as defined in the <sys/socket.h> header,
+       *   to specify the state of the option and linger interval.
+       */
+
+      if (_SO_GETOPT(conn->sconn.s_options, SO_LINGER))
+        {
+          sclock_t expire = DSEC2TICK(conn->sconn.s_linger);
+
+          conn->ltimeout = clock_systime_ticks() + expire;
+
+          /* Update RTO timeout if the work exceeds expire */
+
+          if (work_available(&conn->work) ||

Review Comment:
   let's call tcp_update_timer



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org