Browse Source

Changed behaviour of queryShutdown and querySetup; shutdown no longer
does anything if setup has not been called yet, and they are both only
called when relevant configuration changes are seen (there is always at
least one 'configuration change', the initial setup)

Jelte Jansen 14 years ago
parent
commit
5a036f8ab2
1 changed files with 18 additions and 9 deletions
  1. 18 9
      src/bin/resolver/resolver.cc

+ 18 - 9
src/bin/resolver/resolver.cc

@@ -80,15 +80,19 @@ public:
     }
     }
 
 
     void queryShutdown() {
     void queryShutdown() {
-        dlog("Query shutdown");
-        delete rec_query_;
-        rec_query_ = NULL;
+        // only shut down if we have actually called querySetup before
+        // (this is not a safety check, just to prevent logging of
+        // actions that are not performed
+        if (rec_query_) {
+            dlog("Query shutdown");
+            delete rec_query_;
+            rec_query_ = NULL;
+        }
     }
     }
 
 
     void setForwardAddresses(const vector<addr_t>& upstream,
     void setForwardAddresses(const vector<addr_t>& upstream,
         DNSService *dnss)
         DNSService *dnss)
     {
     {
-        queryShutdown();
         upstream_ = upstream;
         upstream_ = upstream;
         if (dnss) {
         if (dnss) {
             if (upstream_.empty()) {
             if (upstream_.empty()) {
@@ -100,7 +104,6 @@ public:
                     dlog(" " + address.first + ":" +
                     dlog(" " + address.first + ":" +
                         boost::lexical_cast<string>(address.second));
                         boost::lexical_cast<string>(address.second));
                 }
                 }
-                querySetup(*dnss);
             }
             }
         }
         }
     }
     }
@@ -327,8 +330,6 @@ Resolver::~Resolver() {
 
 
 void
 void
 Resolver::setDNSService(asiolink::DNSService& dnss) {
 Resolver::setDNSService(asiolink::DNSService& dnss) {
-    impl_->queryShutdown();
-    impl_->querySetup(dnss);
     dnss_ = &dnss;
     dnss_ = &dnss;
 }
 }
 
 
@@ -514,14 +515,24 @@ Resolver::updateConfig(ConstElementPtr config) {
         }
         }
         // Everything OK, so commit the changes
         // Everything OK, so commit the changes
         // listenAddresses can fail to bind, so try them first
         // listenAddresses can fail to bind, so try them first
+        bool need_query_restart = false;
+        
         if (listenAddressesE) {
         if (listenAddressesE) {
             setListenAddresses(listenAddresses);
             setListenAddresses(listenAddresses);
+            need_query_restart = true;
         }
         }
         if (forwardAddressesE) {
         if (forwardAddressesE) {
             setForwardAddresses(forwardAddresses);
             setForwardAddresses(forwardAddresses);
+            need_query_restart = true;
         }
         }
         if (set_timeouts) {
         if (set_timeouts) {
             setTimeouts(timeout, retries);
             setTimeouts(timeout, retries);
+            need_query_restart = true;
+        }
+
+        if (need_query_restart) {
+            impl_->queryShutdown();
+            impl_->querySetup(*dnss_);
         }
         }
         return (isc::config::createAnswer());
         return (isc::config::createAnswer());
     } catch (const isc::Exception& error) {
     } catch (const isc::Exception& error) {
@@ -596,8 +607,6 @@ Resolver::setTimeouts(int timeout, unsigned retries) {
         " and retry count to " + boost::lexical_cast<string>(retries));
         " and retry count to " + boost::lexical_cast<string>(retries));
     impl_->timeout_ = timeout;
     impl_->timeout_ = timeout;
     impl_->retries_ = retries;
     impl_->retries_ = retries;
-    impl_->queryShutdown();
-    impl_->querySetup(*dnss_);
 }
 }
 pair<int, unsigned>
 pair<int, unsigned>
 Resolver::getTimeouts() const {
 Resolver::getTimeouts() const {