mirror of
https://github.com/apache/nuttx.git
synced 2026-10-03 20:27:53 +00:00
sim/usrsock: Reuse all addresses to avoid bind fail
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
87a8b1bed9
commit
c1c1882783
1 changed files with 8 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue