Browse Source

Better way to stop io_service from running out of work

Instead of detecting when it stopped, use dummy work object to keep it
busy.

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/vorner-recursor-config@3422 e5f2f494-b856-4b98-b285-d166d9295462
Michal Vaner 14 years ago
parent
commit
5049b42830
2 changed files with 6 additions and 17 deletions
  1. 5 11
      src/lib/asiolink/asiolink.cc
  2. 1 6
      src/lib/cc/session.cc

+ 5 - 11
src/lib/asiolink/asiolink.cc

@@ -52,6 +52,8 @@ public:
                   SimpleCallback* checkin, DNSLookup* lookup,
                   DNSAnswer* answer);
     asio::io_service io_service_;
+    // So it does not run out of work when there are no listening sockets
+    asio::io_service::work work_;
 
     typedef boost::shared_ptr<UDPServer> UDPServerPtr;
     typedef boost::shared_ptr<TCPServer> TCPServerPtr;
@@ -107,6 +109,7 @@ IOServiceImpl::IOServiceImpl(const char& port,
                              SimpleCallback* checkin,
                              DNSLookup* lookup,
                              DNSAnswer* answer) :
+    work_(io_service_),
     checkin_(checkin),
     lookup_(lookup),
     answer_(answer)
@@ -187,21 +190,12 @@ IOService::clearServers() {
 
 void
 IOService::run() {
-    if (!impl_->io_service_.run()) {
-        // We got the io_service in stopped state and it didn't work
-        // Reset it and try again
-        impl_->io_service_.reset();
-        impl_->io_service_.run();
-    }
+    impl_->io_service_.run();
 }
 
 void
 IOService::run_one() {
-    if (!impl_->io_service_.run_one()) {
-        // Same as in run() - we got it in stopped state
-        impl_->io_service_.reset();
-        impl_->io_service_.run_one();
-    }
+    impl_->io_service_.run_one();
 }
 
 void

+ 1 - 6
src/lib/cc/session.cc

@@ -182,12 +182,7 @@ SessionImpl::readData(void* data, size_t datalen) {
         // When one of them has a result, cancel the other, and wait
         // until the cancel is processed before we continue
         while (!read_result && !timer_result) {
-            if (!socket_.io_service().run_one()) {
-                // We run out of work last time we did readData
-                // and there seems to be no way to test if it is running.
-                // We know when it returns 0, it is stopped.
-                socket_.io_service().reset();
-            }
+            socket_.io_service().run_one();
 
             // Don't cancel the timer if we haven't set it
             if (read_result && getTimeout() != 0) {