Merge pull request #2064 from garlick/issue_2051

Problem: getifaddrs can fail with ECONNREFUSED
This commit is contained in:
Luca Boccassi 2016-07-20 23:18:00 +01:00 committed by GitHub
commit b2e8a90a97

View File

@ -182,7 +182,16 @@ int zmq::tcp_address_t::resolve_nic_name (const char *nic_, bool ipv6_, bool is_
{
// Get the addresses.
ifaddrs *ifa = NULL;
const int rc = getifaddrs (&ifa);
int rc;
const int max_attempts = 10;
const int backoff_msec = 1;
for (int i = 0; i < max_attempts; i++) {
rc = getifaddrs (&ifa);
if (rc == 0 || (rc < 0 && errno != ECONNREFUSED))
break;
usleep ((backoff_msec << i) * 1000);
}
if (rc != 0 && errno == EINVAL) {
// Windows Subsystem for Linux compatibility
LIBZMQ_UNUSED (nic_);