Browse Source

fix #274

pull/276/head
Max Lv 9 years ago
parent
commit
f8e86c57c0
1 changed files with 11 additions and 1 deletions
  1. 12
      src/server.c

12
src/server.c

@ -34,6 +34,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#include <math.h>
#ifndef __MINGW32__ #ifndef __MINGW32__
#include <netdb.h> #include <netdb.h>
@ -176,7 +177,16 @@ int create_and_bind(const char *host, const char *port)
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; /* For wildcard IP address */ hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; /* For wildcard IP address */
hints.ai_protocol = IPPROTO_TCP; hints.ai_protocol = IPPROTO_TCP;
s = getaddrinfo(host, port, &hints, &result);
for (int i = 0; i < 8; i++) {
s = getaddrinfo(host, port, &hints, &result);
if (s == 0) break;
else {
sleep(pow(2, i));
LOGE("failed to resolve server name, wait for %.0fs", pow(2, i));
}
}
if (s != 0) { if (s != 0) {
LOGE("getaddrinfo: %s", gai_strerror(s)); LOGE("getaddrinfo: %s", gai_strerror(s));
return -1; return -1;

Loading…
Cancel
Save