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

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

commit 8506259b799b76d778f874c18cde645d459e99f9
Author: zhanghongyu <[email protected]>
AuthorDate: Mon Nov 17 14:21:27 2025 +0800

    net/socket: replace net_lock with conn_lock
    
    dup2 and setsockopt can use the lock in conn to protect resources,
    the lock in accept is originally used to protect the connection status.
    however, only the send, recv, netpoll, and connect processes will
    check this flag. only when the interface returns will the corresponding
    conn structure be exposed to the caller, and then the above operations
    can be performed. Therefore, this net_lock is not necessary.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 net/socket/accept.c     | 2 --
 net/socket/net_dup2.c   | 5 +++--
 net/socket/setsockopt.c | 4 ++--
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/socket/accept.c b/net/socket/accept.c
index edb246a509a..073b531fbc0 100644
--- a/net/socket/accept.c
+++ b/net/socket/accept.c
@@ -147,7 +147,6 @@ int psock_accept(FAR struct socket *psock, FAR struct 
sockaddr *addr,
       return -EOPNOTSUPP;
     }
 
-  net_lock();
   ret = psock->s_sockif->si_accept(psock, addr, addrlen, newsock, flags);
   if (ret >= 0)
     {
@@ -166,6 +165,5 @@ int psock_accept(FAR struct socket *psock, FAR struct 
sockaddr *addr,
       nerr("ERROR: si_accept failed: %d\n", ret);
     }
 
-  net_unlock();
   return ret;
 }
diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c
index ad15503442b..50d7969c028 100644
--- a/net/socket/net_dup2.c
+++ b/net/socket/net_dup2.c
@@ -39,6 +39,7 @@
 #include "inet/inet.h"
 #include "tcp/tcp.h"
 #include "socket/socket.h"
+#include "utils/utils.h"
 
 /****************************************************************************
  * Public Functions
@@ -65,7 +66,7 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket 
*psock2)
 {
   /* Parts of this operation need to be atomic */
 
-  net_lock();
+  conn_lock(psock1->s_conn);
 
   /* Duplicate the relevant socket state (zeroing everything else) */
 
@@ -84,7 +85,7 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket 
*psock2)
               psock2->s_sockif->si_addref != NULL);
   psock2->s_sockif->si_addref(psock2);
 
-  net_unlock();
+  conn_unlock(psock1->s_conn);
 
   return OK;
 }
diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c
index 0d0cc013850..f9df34beb55 100644
--- a/net/socket/setsockopt.c
+++ b/net/socket/setsockopt.c
@@ -161,7 +161,7 @@ static int psock_socketlevel_option(FAR struct socket 
*psock, int option,
            * options.
            */
 
-           net_lock();
+          conn_lock(conn);
 
           /* Set or clear the option bit */
 
@@ -174,7 +174,7 @@ static int psock_socketlevel_option(FAR struct socket 
*psock, int option,
               _SO_CLROPT(conn->s_options, option);
             }
 
-          net_unlock();
+          conn_unlock(conn);
         }
         break;
 

Reply via email to