Browse Source

fix bug when port reuse fail (#1037)

pull/1041/head
GhostFlying 8 years ago
committed by Max Lv
parent
commit
c807d2d6c4
1 changed files with 10 additions and 9 deletions
  1. 19
      src/manager.c

19
src/manager.c

@ -356,6 +356,8 @@ create_and_bind(const char *host, const char *port, int protocol)
} }
} }
is_port_reuse = 0;
for (/*rp = result*/; rp != NULL; rp = rp->ai_next) { for (/*rp = result*/; rp != NULL; rp = rp->ai_next) {
listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); listen_sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (listen_sock == -1) { if (listen_sock == -1) {
@ -379,24 +381,23 @@ create_and_bind(const char *host, const char *port, int protocol)
LOGI("%s port reuse enabled", protocol == IPPROTO_TCP ? "tcp" : "udp"); LOGI("%s port reuse enabled", protocol == IPPROTO_TCP ? "tcp" : "udp");
} }
is_port_reuse = 1; is_port_reuse = 1;
} else {
is_port_reuse = 0;
} }
s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen); s = bind(listen_sock, rp->ai_addr, rp->ai_addrlen);
if (s == 0) { if (s == 0) {
/* We managed to bind successfully! */ /* We managed to bind successfully! */
if (!is_port_reuse) {
if (verbose) {
LOGI("close sock due to %s port reuse disabled", protocol == IPPROTO_TCP ? "tcp" : "udp");
}
close(listen_sock);
}
break; break;
} else { } else {
ERROR("bind"); ERROR("bind");
} }
if (!is_port_reuse) {
if (verbose) {
LOGI("close sock due to %s port reuse disabled", protocol == IPPROTO_TCP ? "tcp" : "udp");
}
close(listen_sock);
}
} }
if (!result) { if (!result) {

Loading…
Cancel
Save