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 2022/06/09 10:17:18 UTC

[GitHub] [incubator-nuttx] anchao commented on a diff in pull request #6398: net/tcp: wave hands on background

anchao commented on code in PR #6398:
URL: https://github.com/apache/incubator-nuttx/pull/6398#discussion_r893328660


##########
net/tcp/tcp_close.c:
##########
@@ -40,21 +40,29 @@
 #include "socket/socket.h"
 
 /****************************************************************************
- * Private Types
+ * Private Functions
  ****************************************************************************/
 
-struct tcp_close_s
-{
-  FAR struct tcp_conn_s       *cl_conn;   /* Needed to handle loss of connection */
-  FAR struct devif_callback_s *cl_cb;     /* Reference to TCP callback instance */
-  sem_t                        cl_sem;    /* Signals disconnect completion */
-  int                          cl_result; /* The result of the close */
-};
-
 /****************************************************************************
- * Private Functions
+ * Name: tcp_close_work
  ****************************************************************************/
 
+static void tcp_close_work(FAR void *param)
+{
+  FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)param;
+
+  net_lock();
+
+  tcp_callback_free(conn, conn->clscb);
+
+  /* Stop the network monitor for all sockets */
+
+  tcp_stop_monitor(conn, TCP_CLOSE);
+  tcp_free(param);

Review Comment:
   Done



##########
net/tcp/tcp_close.c:
##########
@@ -307,60 +304,31 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
 
   if ((conn->tcpstateflags == TCP_ESTABLISHED ||
        conn->tcpstateflags == TCP_LAST_ACK) &&
-      (state.cl_cb = tcp_callback_alloc(conn)) != NULL)
+      (conn->clscb = tcp_callback_alloc(conn)) != NULL)
     {
       /* Set up to receive TCP data event callbacks */
 
-      state.cl_cb->flags = (TCP_NEWDATA | TCP_POLL | TCP_DISCONN_EVENTS);
-      state.cl_cb->event = tcp_close_eventhandler;
-
-      /* A non-NULL value of the priv field means that lingering is
-       * enabled.
-       */
-
-      state.cl_cb->priv  = (FAR void *)&state;
-
-      /* Set up for the lingering wait */
-
-      state.cl_conn      = conn;
-      state.cl_result    = -EBUSY;
-
-      /* This semaphore is used for signaling and, hence, should not have
-       * priority inheritance enabled.
-       */
-
-      nxsem_init(&state.cl_sem, 0, 0);
-      nxsem_set_protocol(&state.cl_sem, SEM_PRIO_NONE);
+      conn->clscb->flags = (TCP_NEWDATA | TCP_POLL | TCP_DISCONN_EVENTS);
+      conn->clscb->event = tcp_close_eventhandler;
+      conn->clscb->priv  = conn;
 
       /* Notify the device driver of the availability of TX data */
 
       tcp_close_txnotify(psock, conn);
+    }
+  else
+    {
+      /* Stop the network monitor for all sockets */
 
-      /* Wait for the disconnect event */
-
-      net_lockedwait(&state.cl_sem);
-
-      /* We are now disconnected */
-
-      nxsem_destroy(&state.cl_sem);
-      tcp_callback_free(conn, state.cl_cb);
-
-      /* Free the connection
-       * No more references on the connection
-       */
-
-      conn->crefs = 0;
+      tcp_stop_monitor(conn, TCP_CLOSE);
 
-      /* Get the result of the close */
+      /* Free network resources */
 
-      ret = state.cl_result;
+      tcp_free(conn);
     }
 
-  /* Free network resources */
-
-  tcp_free(conn);
-
   net_unlock();
+

Review Comment:
   Done



-- 
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