Browse Source

[1599] Don't send after being stopped

Michal 'vorner' Vaner 13 years ago
parent
commit
d6d42bcdfc
2 changed files with 15 additions and 3 deletions
  1. 14 2
      src/lib/asiodns/sync_udp_server.cc
  2. 1 1
      src/lib/asiodns/sync_udp_server.h

+ 14 - 2
src/lib/asiodns/sync_udp_server.cc

@@ -47,7 +47,7 @@ SyncUDPServer::SyncUDPServer(asio::io_service& io_service,
                              asiolink::SimpleCallback* checkin,
                              DNSLookup* lookup, DNSAnswer* answer) :
     io_(io_service), checkin_callback_(checkin), lookup_callback_(lookup),
-    answer_callback_(answer)
+    answer_callback_(answer), stopped_(false)
 {
     // We must use different instantiations for v4 and v6;
     // otherwise ASIO will bind to both
@@ -65,7 +65,7 @@ SyncUDPServer::SyncUDPServer(asio::io_service& io_service, const int fd,
                              const int af, asiolink::SimpleCallback* checkin,
                              DNSLookup* lookup, DNSAnswer* answer) :
     io_(io_service), checkin_callback_(checkin), lookup_callback_(lookup),
-    answer_callback_(answer)
+    answer_callback_(answer), stopped_(false)
 {
     if (af != AF_INET && af != AF_INET6) {
         isc_throw(InvalidParameter, "Address family must be either AF_INET "
@@ -122,6 +122,9 @@ SyncUDPServer::handleRead(const asio::error_code& ec, const size_t length) {
     IOMessage message(data_, length, socket, endpoint);
     if (checkin_callback_ != NULL) {
         (*checkin_callback_)(message);
+        if (stopped_) {
+            return;
+        }
     }
 
     // If we don't have a DNS Lookup provider, there's no point in
@@ -150,11 +153,19 @@ SyncUDPServer::handleRead(const asio::error_code& ec, const size_t length) {
                   "No resume called from the lookup callback");
     }
 
+    if (stopped_) {
+        return;
+    }
+
     if (done_) {
         // Good, there's an answer.
         // Call the answer callback to render it.
         (*answer_callback_)(message, query, answer, output);
 
+        if (stopped_) {
+            return;
+        }
+
         socket_->send_to(asio::buffer(output->getData(), output->getLength()),
                          sender_);
     }
@@ -182,6 +193,7 @@ SyncUDPServer::stop() {
     /// submit to io serice before or after close call. And we will
     //. get bad_descriptor error
     socket_->close();
+    stopped_ = true;
 }
 
 /// Post this coroutine on the ASIO service queue so that it will

+ 1 - 1
src/lib/asiodns/sync_udp_server.h

@@ -115,7 +115,7 @@ private:
     const asiolink::SimpleCallback* checkin_callback_;
     const DNSLookup* lookup_callback_;
     const DNSAnswer* answer_callback_;
-    bool resume_called_, done_;
+    bool resume_called_, done_, stopped_;
 
     void scheduleRead();
     void handleRead(const asio::error_code& ec, const size_t length);