mirror of
https://github.com/apache/nuttx.git
synced 2026-05-24 16:11:56 +08:00
sim/usrsock: Reuse all addresses to avoid bind fail
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user