From 75ecbd4382d57580af251bb55e45b7ef207564b7 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 7 Mar 2023 01:38:39 +0800 Subject: [PATCH] net/local: Return the unblock handle correctly in local_accept Signed-off-by: Xiang Xiao --- include/nuttx/net/net.h | 2 +- net/inet/inet_sockif.c | 5 +++-- net/local/local.h | 3 ++- net/local/local_accept.c | 8 +++++--- net/rpmsg/rpmsg_sockif.c | 6 +++--- net/socket/accept.c | 2 +- net/usrsock/usrsock.h | 3 ++- net/usrsock/usrsock_accept.c | 3 ++- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 59bc96ba43..291cba2785 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -156,7 +156,7 @@ struct sock_intf_s FAR const struct sockaddr *addr, socklen_t addrlen); CODE int (*si_accept)(FAR struct socket *psock, FAR struct sockaddr *addr, FAR socklen_t *addrlen, - FAR struct socket *newsock); + FAR struct socket *newsock, int flags); CODE int (*si_poll)(FAR struct socket *psock, FAR struct pollfd *fds, bool setup); CODE ssize_t (*si_sendmsg)(FAR struct socket *psock, diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index 6572b2d417..0b7f5512db 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -76,7 +76,7 @@ static int inet_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, socklen_t addrlen); static int inet_accept(FAR struct socket *psock, FAR struct sockaddr *addr, FAR socklen_t *addrlen, - FAR struct socket *newsock); + FAR struct socket *newsock, int flags); static int inet_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup); static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf, @@ -1369,7 +1369,8 @@ static int inet_connect(FAR struct socket *psock, ****************************************************************************/ static int inet_accept(FAR struct socket *psock, FAR struct sockaddr *addr, - FAR socklen_t *addrlen, FAR struct socket *newsock) + FAR socklen_t *addrlen, FAR struct socket *newsock, + int flags) { #if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK) int ret; diff --git a/net/local/local.h b/net/local/local.h index a3f4b9ab23..6b6bb65cc8 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -347,7 +347,8 @@ int local_listen(FAR struct socket *psock, int backlog); #ifdef CONFIG_NET_LOCAL_STREAM int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, - FAR socklen_t *addrlen, FAR struct socket *newsock); + FAR socklen_t *addrlen, FAR struct socket *newsock, + int flags); #endif /**************************************************************************** diff --git a/net/local/local_accept.c b/net/local/local_accept.c index 1518444389..c198c99ec7 100644 --- a/net/local/local_accept.c +++ b/net/local/local_accept.c @@ -96,12 +96,14 @@ static int local_waitlisten(FAR struct local_conn_s *server) ****************************************************************************/ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, - FAR socklen_t *addrlen, FAR struct socket *newsock) + FAR socklen_t *addrlen, FAR struct socket *newsock, + int flags) { FAR struct local_conn_s *server; FAR struct local_conn_s *client; FAR struct local_conn_s *conn; FAR dq_entry_t *waiter; + bool nonblock = !!(flags & SOCK_NONBLOCK); int ret; /* Some sanity checks */ @@ -180,7 +182,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, * block. */ - ret = local_open_server_tx(conn, false); + ret = local_open_server_tx(conn, nonblock); if (ret < 0) { nerr("ERROR: Failed to open write-only FIFOs for %s: %d\n", @@ -199,7 +201,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, * for writing. */ - ret = local_open_server_rx(conn, false); + ret = local_open_server_rx(conn, nonblock); if (ret < 0) { nerr("ERROR: Failed to open read-only FIFOs for %s: %d\n", diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index 2d8a14d732..583f8d9b33 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -141,7 +141,7 @@ static int rpmsg_socket_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, socklen_t addrlen); static int rpmsg_socket_accept(FAR struct socket *psock, FAR struct sockaddr *addr, FAR socklen_t *addrlen, - FAR struct socket *newsock); + FAR struct socket *newsock, int flags); static int rpmsg_socket_poll(FAR struct socket *psock, FAR struct pollfd *fds, bool setup); static ssize_t rpmsg_socket_sendmsg(FAR struct socket *psock, @@ -737,7 +737,8 @@ static int rpmsg_socket_connect(FAR struct socket *psock, static int rpmsg_socket_accept(FAR struct socket *psock, FAR struct sockaddr *addr, FAR socklen_t *addrlen, - FAR struct socket *newsock) + FAR struct socket *newsock, + int flags) { FAR struct rpmsg_socket_conn_s *server = psock->s_conn; int ret = 0; @@ -787,7 +788,6 @@ static int rpmsg_socket_accept(FAR struct socket *psock, newsock->s_conn = conn; rpmsg_socket_getaddr(conn, addr, addrlen); - break; } else diff --git a/net/socket/accept.c b/net/socket/accept.c index 732fb919c7..75e68031e6 100644 --- a/net/socket/accept.c +++ b/net/socket/accept.c @@ -146,7 +146,7 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, } net_lock(); - ret = psock->s_sockif->si_accept(psock, addr, addrlen, newsock); + ret = psock->s_sockif->si_accept(psock, addr, addrlen, newsock, flags); if (ret >= 0) { /* Mark the new socket as connected. */ diff --git a/net/usrsock/usrsock.h b/net/usrsock/usrsock.h index 8e9fdae651..0eafb8e03f 100644 --- a/net/usrsock/usrsock.h +++ b/net/usrsock/usrsock.h @@ -448,7 +448,8 @@ int usrsock_listen(FAR struct socket *psock, int backlog); ****************************************************************************/ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, - FAR socklen_t *addrlen, FAR struct socket *newsock); + FAR socklen_t *addrlen, FAR struct socket *newsock, + int flags); /**************************************************************************** * Name: usrsock_poll diff --git a/net/usrsock/usrsock_accept.c b/net/usrsock/usrsock_accept.c index 5e84a62aac..a6dfb04609 100644 --- a/net/usrsock/usrsock_accept.c +++ b/net/usrsock/usrsock_accept.c @@ -213,7 +213,8 @@ static int do_accept_request(FAR struct usrsock_conn_s *conn, ****************************************************************************/ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, - FAR socklen_t *addrlen, FAR struct socket *newsock) + FAR socklen_t *addrlen, FAR struct socket *newsock, + int flags) { FAR struct usrsock_conn_s *conn = psock->s_conn; struct usrsock_data_reqstate_s state =