X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fdns.cc;h=0becfc99107f22068e22d512ab9cc2e971989754;hb=91ea3455ccf0cebaecbb2c0ee4ead073b6d86354;hp=3623c4a1f58caa48babff535916e88c141b385ea;hpb=97b73d47e6a3d5729ba13304ff355a737a34f1b4;p=awesomized%2Flibmemcached diff --git a/libtest/dns.cc b/libtest/dns.cc index 3623c4a1..0becfc99 100644 --- a/libtest/dns.cc +++ b/libtest/dns.cc @@ -45,16 +45,28 @@ namespace libtest { bool lookup(const char* host) { - assert(host); bool success= false; - struct addrinfo *addrinfo= NULL; - - int limit= 5; - while (limit--) + if (host) { - int ret; - if ((ret= getaddrinfo(host, NULL, NULL, &(addrinfo)))) + assert(host); + struct addrinfo *addrinfo= NULL; + + int limit= 5; + while (--limit and success == false) { + if (addrinfo) + { + freeaddrinfo(addrinfo); + addrinfo= NULL; + } + + int ret; + if ((ret= getaddrinfo(host, NULL, NULL, &addrinfo)) == 0) + { + success= true; + break; + } + switch (ret) { case EAI_AGAIN: @@ -64,16 +76,16 @@ bool lookup(const char* host) default: break; } + + break; } - else + + if (addrinfo) { - success= true; - break; + freeaddrinfo(addrinfo); } } - freeaddrinfo(addrinfo); - return success; } @@ -87,7 +99,7 @@ bool check_dns() if (lookup("does_not_exist.gearman.info")) // This should fail, if it passes,... { - return false; + fatal_assert("Your service provider sucks and is providing bogus DNS. You might be in an airport."); } return true;