You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/12/18 19:15:52 UTC
[incubator-nuttx] branch master updated: sim/usrsock: Reuse all addresses to avoid bind fail
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new c1c1882 sim/usrsock: Reuse all addresses to avoid bind fail
c1c1882 is described below
commit c1c1882783e70edbc21f1ae4705d2ddd2e7ddb76
Author: chao.an <an...@xiaomi.com>
AuthorDate: Sat Dec 18 21:43:28 2021 +0800
sim/usrsock: Reuse all addresses to avoid bind fail
Signed-off-by: chao.an <an...@xiaomi.com>
---
arch/sim/src/sim/up_usrsock_host.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/sim/src/sim/up_usrsock_host.c b/arch/sim/src/sim/up_usrsock_host.c
index d6428fc..ed701de 100644
--- a/arch/sim/src/sim/up_usrsock_host.c
+++ b/arch/sim/src/sim/up_usrsock_host.c
@@ -187,6 +187,7 @@ static int usrsock_host_sockopt(int sockfd, int level, int optname,
int usrsock_host_socket(int domain, int type, int protocol)
{
+ int opt = 1;
int ret;
if (domain == NUTTX_PF_INET)
@@ -238,6 +239,12 @@ int usrsock_host_socket(int domain, int type, int protocol)
return -errno;
}
+ /* Reuse all addresses to avoid bind fail if the
+ * nuttx exits unexpectedly.
+ */
+
+ setsockopt(ret, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+
sock_nonblock(ret, true);
usrsock_host_set_fd(ret, &g_active_read_fds);
@@ -435,6 +442,7 @@ int usrsock_host_listen(int sockfd, int backlog)
int usrsock_host_accept(int sockfd, struct nuttx_sockaddr *addr,
nuttx_socklen_t *addrlen)
{
+ socklen_t naddrlen = sizeof(socklen_t);
struct sockaddr naddr;
socklen_t naddrlen;
int ret;