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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-17 14:21:27 +08:00
committed by Alan C. Assis
parent 3a0ab84855
commit 8506259b79
3 changed files with 5 additions and 6 deletions
-2
View File
@@ -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;
}
+3 -2
View File
@@ -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;
}
+2 -2
View File
@@ -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;