Browse Source

Fix #966 again (#967)

* SO_REUSEADDR for remote sockfd

avoid  ERROR: bind_to_address: Address already in use

* set addr->sin_port to be 0

* Update server.c

* Update server.c

* Update server.c

* Update server.c

* Update server.c

* Update server.c

* Update server.c
pull/975/head
tim-le 8 years ago
committed by Max Lv
parent
commit
aca5f5ddb4
1 changed files with 7 additions and 4 deletions
  1. 11
      src/server.c

11
src/server.c

@ -519,16 +519,17 @@ connect_to_remote(EV_P_ struct addrinfo *res,
#endif
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
remote_t *remote = new_remote(sockfd);
// setup remote socks
if (setnonblocking(sockfd) == -1)
ERROR("setnonblocking");
if (bind_address != NULL)
if (bind_to_address(sockfd, bind_address) == -1)
FATAL("unable to bind the specific address");
if (bind_to_address(sockfd, bind_address) == -1) {
ERROR("bind_to_address");
close(sockfd);
return NULL;
}
#ifdef SET_INTERFACE
if (iface) {
@ -537,6 +538,8 @@ connect_to_remote(EV_P_ struct addrinfo *res,
}
#endif
remote_t *remote = new_remote(sockfd);
#ifdef TCP_FASTOPEN
if (fast_open) {
#ifdef __APPLE__

Loading…
Cancel
Save