Browse Source

Loop when getting EAI_AGAIN error with getaddrinfo.

master
Con Kolivas 8 years ago
parent
commit
718c2dcadf
  1. 24
      src/libckpool.c

24
src/libckpool.c

@ -539,6 +539,22 @@ bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port)
return true; return true;
} }
/* Helper for getaddrinfo with the same API that retries while getting
* EAI_AGAIN error */
static int addrgetinfo(const char *node, const char *service,
const struct addrinfo *hints,
struct addrinfo **res)
{
int ret;
do {
ret = getaddrinfo(node, service, hints, res);
} while (ret == EAI_AGAIN);
return ret;
}
bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addrinfo) bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addrinfo)
{ {
struct addrinfo *servinfo, hints; struct addrinfo *servinfo, hints;
@ -547,7 +563,7 @@ bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addri
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
servinfo = addrinfo; servinfo = addrinfo;
if (getaddrinfo(url, port, &hints, &servinfo) != 0) if (addrgetinfo(url, port, &hints, &servinfo) != 0)
return false; return false;
if (!servinfo) if (!servinfo)
return false; return false;
@ -662,7 +678,7 @@ int bind_socket(char *url, char *port)
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
servinfo = &servinfobase; servinfo = &servinfobase;
if (getaddrinfo(url, port, &hints, &servinfo) != 0) { if (addrgetinfo(url, port, &hints, &servinfo) != 0) {
LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port); LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port);
return sockd; return sockd;
} }
@ -699,7 +715,7 @@ int connect_socket(char *url, char *port)
memset(&servinfobase, 0, sizeof(struct addrinfo)); memset(&servinfobase, 0, sizeof(struct addrinfo));
servinfo = &servinfobase; servinfo = &servinfobase;
if (getaddrinfo(url, port, &hints, &servinfo) != 0) { if (addrgetinfo(url, port, &hints, &servinfo) != 0) {
LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port); LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port);
goto out; goto out;
} }
@ -771,7 +787,7 @@ int round_trip(char *url)
memset(&servinfobase, 0, sizeof(struct addrinfo)); memset(&servinfobase, 0, sizeof(struct addrinfo));
p = &servinfobase; p = &servinfobase;
if (getaddrinfo(url, port, &hints, &p) != 0) { if (addrgetinfo(url, port, &hints, &p) != 0) {
LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port); LOGWARNING("Failed to resolve (?wrong URL) %s:%s", url, port);
return ret; return ret;
} }

Loading…
Cancel
Save