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 6bed8c4cb16009d040f73b1a7c1f9c1181a901c7
Author: Yongrong Wang <[email protected]>
AuthorDate: Fri Jun 20 11:06:01 2025 +0800

    vsock_sockif.c: fix vsock connect close error in nonblcok mode
    
    If the client has not received a response after sending a request message,
    but the upper layer immediately calls close, the close process is not
    executed correctly.
    
    Signed-off-by: Yongrong Wang <[email protected]>
---
 include/nuttx/net/net.h  | 14 ++++++++------
 net/vsock/vsock_sockif.c |  4 +++-
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 0a78bc2c59e..edc7c0aca82 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -54,6 +54,7 @@
 /* Definitions of 8-bit socket flags */
 
 #define _SF_INITD           0x01  /* Bit 0: Socket structure is initialized */
+#define _SF_CONNECTING      0x02  /* Bit 1: SOCK_STREAM is connecting */
 #define _SF_NONBLOCK        0x08  /* Bit 3: Don't block if no data (TCP/READ 
only) */
 #define _SF_LISTENING       0x10  /* Bit 4: SOCK_STREAM is listening */
 #define _SF_BOUND           0x20  /* Bit 5: SOCK_STREAM is bound to an address 
*/
@@ -71,12 +72,13 @@
 
 /* Macro to manage the socket state and flags */
 
-#define _SS_INITD(s)        (((s) & _SF_INITD)     != 0)
-#define _SS_ISNONBLOCK(s)   (((s) & _SF_NONBLOCK)  != 0)
-#define _SS_ISLISTENING(s)  (((s) & _SF_LISTENING) != 0)
-#define _SS_ISBOUND(s)      (((s) & _SF_BOUND)     != 0)
-#define _SS_ISCONNECTED(s)  (((s) & _SF_CONNECTED) != 0)
-#define _SS_ISCLOSED(s)     (((s) & _SF_CLOSED)    != 0)
+#define _SS_INITD(s)        (((s) & _SF_INITD)      != 0)
+#define _SS_ISCONNECTING(s) (((s) & _SF_CONNECTING) != 0)
+#define _SS_ISNONBLOCK(s)   (((s) & _SF_NONBLOCK)   != 0)
+#define _SS_ISLISTENING(s)  (((s) & _SF_LISTENING)  != 0)
+#define _SS_ISBOUND(s)      (((s) & _SF_BOUND)      != 0)
+#define _SS_ISCONNECTED(s)  (((s) & _SF_CONNECTED)  != 0)
+#define _SS_ISCLOSED(s)     (((s) & _SF_CLOSED)     != 0)
 
 /* Determine if a socket is valid.  Valid means both (1) allocated and (2)
  * successfully initialized:
diff --git a/net/vsock/vsock_sockif.c b/net/vsock/vsock_sockif.c
index 60b445d0615..9f7d3c0780c 100644
--- a/net/vsock/vsock_sockif.c
+++ b/net/vsock/vsock_sockif.c
@@ -1692,6 +1692,7 @@ static int vsock_connect(FAR struct socket *psock,
       goto err_with_bind;
     }
 
+  conn->sconn.s_flags |= _SF_CONNECTING;
   if (_SS_ISNONBLOCK(conn->sconn.s_flags))
     {
       ret = -EINPROGRESS;
@@ -2147,7 +2148,8 @@ static int vsock_close(FAR struct socket *psock)
                conn, conn->sconn.s_flags);
       vsock_remove_conn(conn);
     }
-  else if (_SS_ISCONNECTED(conn->sconn.s_flags))
+  else if (_SS_ISCONNECTED(conn->sconn.s_flags) ||
+           _SS_ISCONNECTING(conn->sconn.s_flags))
     {
       vsock_add_ref(conn);
       conn->shutdown = SHUT_RDWR;

Reply via email to