diff options
author | louiz’ <louiz@louiz.org> | 2017-03-07 17:47:10 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2017-03-07 17:47:10 +0100 |
commit | 6cb7787512a5e02ad2100dbdef734b36d8a8f0d5 (patch) | |
tree | 9cd6c5fb78fcfc4766c8e68694ce7bd2a30d2182 /louloulibs | |
parent | d2f4235ebf8af640fa915e067f0824da0454be87 (diff) | |
download | biboumi-6cb7787512a5e02ad2100dbdef734b36d8a8f0d5.tar.gz biboumi-6cb7787512a5e02ad2100dbdef734b36d8a8f0d5.tar.bz2 biboumi-6cb7787512a5e02ad2100dbdef734b36d8a8f0d5.tar.xz biboumi-6cb7787512a5e02ad2100dbdef734b36d8a8f0d5.zip |
Small resolver refactor
Makes the codecoverage deterministic (it does not depend on the order of
v4/v6 resolution)
Diffstat (limited to 'louloulibs')
-rw-r--r-- | louloulibs/network/resolver.cpp | 17 | ||||
-rw-r--r-- | louloulibs/network/resolver.hpp | 4 |
2 files changed, 12 insertions, 9 deletions
diff --git a/louloulibs/network/resolver.cpp b/louloulibs/network/resolver.cpp index 0655b1b..27a515e 100644 --- a/louloulibs/network/resolver.cpp +++ b/louloulibs/network/resolver.cpp @@ -113,12 +113,14 @@ void Resolver::start_resolving(const std::string& hostname, const std::string& p { Resolver* resolver = static_cast<Resolver*>(data); resolver->on_hostname6_resolved(result); + resolver->after_resolved(); }; auto hostname4_resolved = [](dns_ctx*, dns_rr_a4* result, void* data) { Resolver* resolver = static_cast<Resolver*>(data); resolver->on_hostname4_resolved(result); + resolver->after_resolved(); }; DNSHandler::watch(); @@ -173,9 +175,6 @@ std::vector<std::string> Resolver::look_in_etc_hosts(const std::string &hostname void Resolver::on_hostname4_resolved(dns_rr_a4 *result) { - if (dns_active(nullptr) == 0) - DNSHandler::unwatch(); - this->resolved4 = true; const auto status = dns_status(nullptr); @@ -196,16 +195,10 @@ void Resolver::on_hostname4_resolved(dns_rr_a4 *result) if (error != end(dns_error_messages)) this->error_msg = error->second; } - - if (this->resolved6 && this->resolved4) - this->on_resolved(); } void Resolver::on_hostname6_resolved(dns_rr_a6 *result) { - if (dns_active(nullptr) == 0) - DNSHandler::unwatch(); - this->resolved6 = true; char buf[INET6_ADDRSTRLEN]; @@ -219,6 +212,12 @@ void Resolver::on_hostname6_resolved(dns_rr_a6 *result) this->call_getaddrinfo(buf, this->port.data(), AI_NUMERICHOST); } } +} + +void Resolver::after_resolved() +{ + if (dns_active(nullptr) == 0) + DNSHandler::unwatch(); if (this->resolved6 && this->resolved4) this->on_resolved(); diff --git a/louloulibs/network/resolver.hpp b/louloulibs/network/resolver.hpp index 800c7ec..a560819 100644 --- a/louloulibs/network/resolver.hpp +++ b/louloulibs/network/resolver.hpp @@ -89,6 +89,10 @@ private: #ifdef UDNS_FOUND void on_hostname4_resolved(dns_rr_a4 *result); void on_hostname6_resolved(dns_rr_a6 *result); + /** + * Called after one record (4 or 6) has been resolved. + */ + void after_resolved(); void start_timer(); |