]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3315] use stopAndPoll
authorRazvan Becheriu <razvan@isc.org>
Mon, 22 Apr 2024 17:46:43 +0000 (20:46 +0300)
committerRazvan Becheriu <razvan@isc.org>
Mon, 22 Apr 2024 20:00:29 +0000 (23:00 +0300)
68 files changed:
src/bin/agent/ca_process.cc
src/bin/agent/tests/ca_command_mgr_unittests.cc
src/bin/agent/tests/ca_process_unittests.cc
src/bin/d2/d2_hooks.dox
src/bin/d2/d2_process.cc
src/bin/d2/tests/d2_process_unittests.cc
src/bin/d2/tests/d2_queue_mgr_unittests.cc
src/bin/d2/tests/d2_update_mgr_unittests.cc
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp4/dhcp4_hooks.dox
src/bin/dhcp4/dhcp4_srv.cc
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/bin/dhcp6/dhcp6_hooks.dox
src/bin/dhcp6/dhcp6_srv.cc
src/bin/dhcp6/json_config_parser.cc
src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
src/bin/dhcp6/tests/dhcp6_test_utils.h
src/bin/netconf/http_control_socket.cc
src/bin/netconf/netconf_process.cc
src/bin/netconf/tests/control_socket_unittests.cc
src/bin/netconf/tests/netconf_process_unittests.cc
src/bin/netconf/tests/netconf_unittests.cc
src/hooks/dhcp/high_availability/ha.dox
src/hooks/dhcp/high_availability/ha_callouts.cc
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_test.cc
src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc
src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc
src/lib/asiodns/tests/io_fetch_unittest.cc
src/lib/asiolink/io_service.cc
src/lib/asiolink/io_service.h
src/lib/asiolink/io_service_mgr.cc
src/lib/asiolink/io_service_mgr.h
src/lib/asiolink/process_spawn.cc
src/lib/asiolink/tests/interval_timer_unittest.cc
src/lib/asiolink/tests/io_service_mgr_unittest.cc
src/lib/asiolink/tests/process_spawn_unittest.cc
src/lib/asiolink/tests/tcp_acceptor_unittest.cc
src/lib/asiolink/tests/tls_acceptor_unittest.cc
src/lib/asiolink/tests/tls_unittest.cc
src/lib/asiolink/tests/unix_domain_socket_unittest.cc
src/lib/config/cmd_http_listener.cc
src/lib/config/tests/client_connection_unittests.cc
src/lib/config/tests/cmd_http_listener_unittests.cc
src/lib/d2srv/tests/dns_client_unittests.cc
src/lib/d2srv/tests/nc_trans_unittests.cc
src/lib/d2srv/testutils/nc_test_utils.cc
src/lib/dhcp_ddns/ncr_io.cc
src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
src/lib/dhcpsrv/d2_client_mgr.cc
src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
src/lib/http/client.cc
src/lib/http/tests/client_mt_unittests.cc
src/lib/http/tests/connection_pool_unittests.cc
src/lib/http/tests/server_client_unittests.cc
src/lib/http/tests/tls_client_unittests.cc
src/lib/http/tests/tls_server_unittests.cc
src/lib/process/d_process.h
src/lib/tcp/mt_tcp_listener_mgr.cc
src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
src/lib/tcp/tests/tcp_listener_unittests.cc
src/lib/tcp/tests/tls_listener_unittests.cc

index 2bfa6a77b644827dcb09a5ea0304277afb7f1f13..2403eedb1a64d93edbad9dc68455a4d088e99011 100644 (file)
@@ -90,6 +90,7 @@ CtrlAgentProcess::run() {
 
 size_t
 CtrlAgentProcess::runIO() {
+    // Handle events registered by hooks using external IOService objects.
     IOServiceMgr::instance().pollIOServices();
     size_t cnt = getIOService()->poll();
     if (!cnt) {
@@ -195,8 +196,9 @@ CtrlAgentProcess::configure(isc::data::ConstElementPtr config_set,
     int rcode = 0;
     config::parseAnswer(rcode, answer);
 
-    /// Let postponed hook initializations to run.
+    /// Let postponed hook initializations run.
     try {
+        // Handle events registered by hooks using external IOService objects.
         IOServiceMgr::instance().pollIOServices();
     } catch (const std::exception& ex) {
         std::ostringstream err;
index bd25e58cbfd5915624d32562ab74b46d44b12880..4cef0426cd69a81286bfa36c8003c87d1d7f09fb 100644 (file)
@@ -248,9 +248,7 @@ public:
 
         // We have some cancelled operations for which we need to invoke the
         // handlers with the operation_aborted error code.
-        getIOService()->stop();
-        getIOService()->restart();
-        getIOService()->poll();
+        getIOService()->stopAndPoll(false);
 
         EXPECT_EQ(expected_responses, server_socket_->getResponseNum());
         checkAnswer(answer, expected_result0, expected_result1, expected_result2);
@@ -414,9 +412,7 @@ TEST_F(CtrlAgentCommandMgrTest, forwardListCommands) {
 
     // We have some cancelled operations for which we need to invoke the
     // handlers with the operation_aborted error code.
-    getIOService()->stop();
-    getIOService()->restart();
-    getIOService()->poll();
+    getIOService()->stopAndPoll(false);
 
     // Answer of 3 is specific to the stub response we send when the
     // command is forwarded. So having this value returned means that
index 15b414e4b758473f86b7d7acde933e8222892d52..67f4aa0f57aedf5a10a9e65c142ae19f02c914c2 100644 (file)
@@ -86,12 +86,7 @@ TEST_F(CtrlAgentProcessTest, shutdown) {
                 elapsed.total_milliseconds() <= 400);
 
     timer.cancel();
-    getIOService()->stop();
-    getIOService()->restart();
-    try {
-        getIOService()->poll();
-    } catch (...) {
-    }
+    getIOService()->stopAndPoll();
 }
 
 }
index a01525b5d4cb84b10394291e829693f53000aff5..9fe8ebbc0a98ce2cea54036ca0ebef74dcb54aed 100644 (file)
@@ -57,7 +57,7 @@ to the end of this list.
    its (re)configuration. The server provides received and parsed configuration
    structures to the hook library.
    If the library uses any IO operations, it should create a local IOService
-   object and register it to the IOServiceMgr. This way the local IOService is
+   object and register it with the IOServiceMgr. This way the local IOService is
    used by the server to run asynchronous operations. The hooks library can use
    the local IOService object to schedule asynchronous tasks which are triggered
    by the D2 server's main loop. The hook library can use the local IOService
index 1e741697e9be6e614dea309f9d7ac5c043c1c3cb..75d0704551ab892881f915ee6b0ab01d713ad62d 100644 (file)
@@ -131,6 +131,7 @@ D2Process::run() {
 
 size_t
 D2Process::runIO() {
+    // Handle events registered by hooks using external IOService objects.
     IOServiceMgr::instance().pollIOServices();
     // We want to block until at least one handler is called.  We'll use
     // boost::asio::io_service directly for two reasons. First off
@@ -303,8 +304,9 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
         }
     }
 
-    /// Let postponed hook initializations to run.
+    /// Let postponed hook initializations run.
     try {
+        // Handle events registered by hooks using external IOService objects.
         IOServiceMgr::instance().pollIOServices();
     } catch (const std::exception& ex) {
         std::ostringstream err;
@@ -452,12 +454,7 @@ D2Process::reconfigureQueueMgr() {
 
 D2Process::~D2Process() {
     queue_mgr_->stopListening();
-    getIOService()->stop();
-    getIOService()->restart();
-    try {
-        getIOService()->poll();
-    } catch (...) {
-    }
+    getIOService()->stopAndPoll();
     queue_mgr_->removeListener();
 }
 
index 83ae4001297cbb05de9bbb327e649e97d670f025..b4fb7ae907ecc6c21125c8d127f80d724bc19470 100644 (file)
@@ -585,12 +585,7 @@ TEST_F(D2ProcessTest, normalShutdown) {
                 elapsed.total_milliseconds() <= 2200);
 
     timer.cancel();
-    getIOService()->stop();
-    getIOService()->restart();
-    try {
-        getIOService()->poll();
-    } catch (...) {
-    }
+    getIOService()->stopAndPoll();
 }
 
 /// @brief Verifies that an "uncaught" exception thrown during event loop
@@ -617,12 +612,7 @@ TEST_F(D2ProcessTest, fatalErrorShutdown) {
                 elapsed.total_milliseconds() <= 2200);
 
     timer.cancel();
-    getIOService()->stop();
-    getIOService()->restart();
-    try {
-        getIOService()->poll();
-    } catch (...) {
-    }
+    getIOService()->stopAndPoll();
 }
 
 /// @brief Used to permit visual inspection of logs to ensure
index 16d99985673b2a92e220ea637ad9883474b01a8f..97a21d88a6f17fcbbbc703f23b221a9b3c2a9a7c 100644 (file)
@@ -250,12 +250,7 @@ public:
         sender_->stopSending();
         queue_mgr_->stopListening();
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         queue_mgr_->removeListener();
     }
 
index 71ba0fb277fe00ed8d61354928a16c746b0ff696..0c0262285f14e4c5c70661dd3239de902f8f001d 100644 (file)
@@ -85,12 +85,7 @@ public:
         if (server_) {
             server_->stop();
         }
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Creates a list of valid NameChangeRequest.
index 2e8af5434c3ab1c3fd7c4bf4646ca01e09900b69..aecc2c6d7c498d3e80a3591492f3d6dea5ac49e1 100644 (file)
@@ -453,8 +453,9 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
         LOG_FATAL(dhcp4_logger, DHCP4_CONFIG_UNRECOVERABLE_ERROR);
     }
 
-    /// Let postponed hook initializations to run.
+    /// Let postponed hook initializations run.
     try {
+        // Handle events registered by hooks using external IOService objects.
         IOServiceMgr::instance().pollIOServices();
     } catch (const std::exception& ex) {
         std::ostringstream err;
index cb8c699a2070a1568a2b23f944550c6174bce414..45bc9db30ad91b80fe67733b5b66bd6271b4b381 100644 (file)
@@ -57,7 +57,7 @@ to the end of this list.
    its (re)configuration. The server provides received and parsed configuration
    structures to the hook library.
    If the library uses any IO operations, it should create a local IOService
-   object and register it to the IOServiceMgr. This way the local IOService is
+   object and register it with the IOServiceMgr. This way the local IOService is
    used by the server to run asynchronous operations. The hooks library can use
    the local IOService object to schedule asynchronous tasks which are triggered
    by the DHCP server's main loop. The hook library can use the local IOService
index 14ab46a1dfa5f6cf32e321719328d42eef940741..be0e78c5325f3d3bd85137f6a7c5c5bfe37369f6 100644 (file)
@@ -708,12 +708,7 @@ Dhcpv4Srv::~Dhcpv4Srv() {
         LOG_ERROR(dhcp4_logger, DHCP4_SRV_UNLOAD_LIBRARIES_ERROR).arg(msg);
     }
     IOServiceMgr::instance().clearIOServices();
-    io_service_->stop();
-    io_service_->restart();
-    try {
-        io_service_->poll();
-    } catch (...) {
-    }
+    io_service_->stopAndPoll();
 }
 
 void
@@ -1134,6 +1129,7 @@ Dhcpv4Srv::run() {
 #endif // ENABLE_AFL
         try {
             runOne();
+            // Handle events registered by hooks using external IOService objects.
             IOServiceMgr::instance().pollIOServices();
             getIOService()->poll();
         } catch (const std::exception& e) {
index 9ab0c886c5214c5dd5743bd1761f001faa9ccfb9..0b1b7e2e3b26726f12b70050d8bb7aa5cda7e797 100644 (file)
@@ -937,8 +937,9 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
                 return (notify_libraries);
             }
 
-            /// Let postponed hook initializations to run.
+            /// Let postponed hook initializations run.
             try {
+                // Handle events registered by hooks using external IOService objects.
                 IOServiceMgr::instance().pollIOServices();
             } catch (const std::exception& ex) {
                 std::ostringstream err;
index 35dbe1e0435787f413b777aca71c7e767e26f9cc..b8314843d8a23088707ac9b416cb165bfc3ccd5a 100644 (file)
@@ -455,8 +455,9 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
         LOG_FATAL(dhcp6_logger, DHCP6_CONFIG_UNRECOVERABLE_ERROR);
     }
 
-    /// Let postponed hook initializations to run.
+    /// Let postponed hook initializations run.
     try {
+        // Handle events registered by hooks using external IOService objects.
         IOServiceMgr::instance().pollIOServices();
     } catch (const std::exception& ex) {
         std::ostringstream err;
index d2b30879508ce6cb64b4c396f40122c872c1f783..862db7f4e44c0c395ada1f64994e3d438d40baea 100644 (file)
@@ -57,7 +57,7 @@ to the end of this list.
    its (re)configuration. The server provides received and parsed configuration
    structures to the hook library.
    If the library uses any IO operations, it should create a local IOService
-   object and register it to the IOServiceMgr. This way the local IOService is
+   object and register it with the IOServiceMgr. This way the local IOService is
    used by the server to run asynchronous operations. The hooks library can use
    the local IOService object to schedule asynchronous tasks which are triggered
    by the DHCP server's main loop. The hook library can use the local IOService
index 205bf5d23dc1aeac03b4ef06bdf672c938e77c76..49fe1a1865189395815fa05b36a0426466e3e4a0 100644 (file)
@@ -304,12 +304,7 @@ Dhcpv6Srv::~Dhcpv6Srv() {
         LOG_ERROR(dhcp6_logger, DHCP6_SRV_UNLOAD_LIBRARIES_ERROR).arg(msg);
     }
     IOServiceMgr::instance().clearIOServices();
-    io_service_->stop();
-    io_service_->restart();
-    try {
-        io_service_->poll();
-    } catch (...) {
-    }
+    io_service_->stopAndPoll();
 }
 
 void Dhcpv6Srv::shutdown() {
@@ -615,6 +610,7 @@ Dhcpv6Srv::run() {
 #endif // ENABLE_AFL
         try {
             runOne();
+            // Handle events registered by hooks using external IOService objects.
             IOServiceMgr::instance().pollIOServices();
             getIOService()->poll();
         } catch (const std::exception& e) {
index 8de39074383127965ca0193c80fe826437bd7f39..7783f4142ea8430c2393d43012edc7d881bebb96 100644 (file)
@@ -1070,8 +1070,9 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
                 return (notify_libraries);
             }
 
-            /// Let postponed hook initializations to run.
+            /// Let postponed hook initializations run.
             try {
+                // Handle events registered by hooks using external IOService objects.
                 IOServiceMgr::instance().pollIOServices();
             } catch (const std::exception& ex) {
                 std::ostringstream err;
index ad747214b96cccfed18c1794c1c6702a8fa8db86..3e2c5550da30aad8bd21e54adbbca8bbb2290137 100644 (file)
@@ -21,7 +21,7 @@ export KEA_LFC_EXECUTABLE="@abs_top_builddir@/src/bin/lfc/kea-lfc"
 # Path to test hooks library
 HOOK_FAIL_LOAD_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco3.so"
 # Path to test hooks library
-HOOK_FAIL_POLL_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco3.so"
+HOOK_FAIL_POLL_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco4.so"
 # Kea configuration to be stored in the configuration file.
 CONFIG="{
     \"Dhcp6\":
index e519a6e267ddf6c0d5e8bb1ad7d067234070bfe3..ddcd64a8a2afc9fabe156f68c5a84add49bf4636 100644 (file)
@@ -218,12 +218,7 @@ public:
     virtual ~NakedDhcpv6Srv() {
         // Close the lease database
         isc::dhcp::LeaseMgrFactory::destroy();
-        getIOService()->stop();
-        getIOService()->restart();
-        try {
-            getIOService()->poll();
-        } catch (...) {
-        }
+        getIOService()->stopAndPoll();
     }
 
     /// @brief Processes incoming Solicit message.
index aa69a5054ec3c5a3ae0c6dc0edb863a23c47b541..12b240232fc63ed3c764bb84128f0c096db73019 100644 (file)
@@ -102,12 +102,7 @@ HttpControlSocket::sendCommand(ConstElementPtr command) {
     io_service->run();
 
     client.stop();
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     if (received_ec) {
         // Got an error code.
index 2e86a9bee0ad401e02c7b2f592f907d9d2add5b4..2d97510302570caa30b9ecd2535433875ec42a62 100644 (file)
@@ -66,6 +66,7 @@ NetconfProcess::run() {
 
 size_t
 NetconfProcess::runIO() {
+    // Handle events registered by hooks using external IOService objects.
     IOServiceMgr::instance().pollIOServices();
     size_t cnt = getIOService()->poll();
     if (!cnt) {
@@ -88,8 +89,9 @@ NetconfProcess::configure(isc::data::ConstElementPtr config_set,
     int rcode = 0;
     config::parseAnswer(rcode, answer);
 
-    /// Let postponed hook initializations to run.
+    /// Let postponed hook initializations run.
     try {
+        // Handle events registered by hooks using external IOService objects.
         IOServiceMgr::instance().pollIOServices();
     } catch (const std::exception& ex) {
         std::ostringstream err;
index f9f74f7a6707435ecaecb2a38ba61a06aad223d1..5f211cf8e5ffcb601485a07054c769ad0facf8ae 100644 (file)
@@ -158,12 +158,7 @@ public:
             thread_.reset();
         }
         removeUnixSocketFile();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Returns socket file path.
@@ -530,12 +525,7 @@ public:
         if (listener_) {
             listener_->stop();
         }
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         listener_.reset();
     }
 
index 563dc3df501f9bb13d7d848a9916fcdda01d7985..7746806e8f31ac20e96a6d7b845d67d684cf6e6e 100644 (file)
@@ -81,12 +81,7 @@ TEST_F(NetconfProcessTest, shutdown) {
     EXPECT_TRUE(elapsed.total_milliseconds() >= 100 &&
                 elapsed.total_milliseconds() <= 400);
     timer.cancel();
-    getIOService()->stop();
-    getIOService()->restart();
-    try {
-        getIOService()->poll();
-    } catch (...) {
-    }
+    getIOService()->stopAndPoll();
 }
 
 }
index 2efc99f74ecdea7fc0168b92abdcf836fc4ba81b..448453cd6362c82bedf7811899b8ba69ad2f9351 100644 (file)
@@ -130,12 +130,7 @@ public:
         responses_.clear();
         removeUnixSocketFile();
         SysrepoSetup::cleanSharedMemory();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Returns socket file path.
index 2ac714f9875022001709c013d78da94d5fe0f731..66f5402e23c09a48ec430a1906cc008b430aec85 100644 (file)
@@ -137,8 +137,8 @@ IOServiceMgr::instance().pollIOServices();
 which executes callbacks for completed asynchronous operations, such as
 timers, asynchronous sends and receives. The instance of the IOService
 is owned by the DHCP servers, but hooks libraries must create their own
-IOService access to schedule asynchronous tasks.
-The hook's IOService object must be registered on the IOServiceMgr by
+IOService to schedule asynchronous tasks.
+The hook's IOService object must be registered with the IOServiceMgr by
 calling registerIOService and must unregister it on "unload" hook point
 by calling unregisterIOService.
 
@@ -163,6 +163,7 @@ Dhcpv[4|6]Srv::run() {
 [...]
         try {
             runOne();
+            // Handle events registered by hooks using external IOService objects.
             IOServiceMgr::instance().pollIOServices();
             getIOService()->poll();
         } catch (const std::exception& e) {
index 014080f8e8f9146c1dfa8d28c82d3ebdac795f09..2e4410983b3be70478d7d10c2d00f7e120764c5b 100644 (file)
@@ -430,12 +430,7 @@ int load(LibraryHandle& handle) {
 int unload() {
     if (impl) {
         IOServiceMgr::instance().unregisterIOService(impl->getIOService());
-        impl->getIOService()->stop();
-        impl->getIOService()->restart();
-        try {
-            impl->getIOService()->poll();
-        } catch (...) {
-        }
+        impl->getIOService()->stopAndPoll();
     }
     impl.reset();
     LOG_INFO(ha_logger, HA_DEINIT_OK);
index 1dfa8f322b16da43fbe210450e9bbc674857afb1..997ae1311a3cd53d58993ca36456dc65737f2b83 100644 (file)
@@ -2465,12 +2465,7 @@ HAService::synchronize(std::string& status_message,
 
     client.stop();
 
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     // If an error message has been recorded, return an error to the controlling
     // client.
@@ -2612,12 +2607,7 @@ HAService::sendLeaseUpdatesFromBacklog() {
 
     client.stop();
 
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     if (updates_successful) {
         LOG_INFO(ha_logger, HA_LEASES_BACKLOG_SUCCESS)
@@ -2700,12 +2690,7 @@ HAService::sendHAReset() {
 
     client.stop();
 
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     return (reset_successful);
 }
@@ -2868,12 +2853,7 @@ HAService::processMaintenanceStart() {
 
     client.stop();
 
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     // If there was a communication problem with the partner we assume that
     // the partner is already down while we receive this command.
@@ -2991,12 +2971,7 @@ HAService::processMaintenanceCancel() {
 
     client.stop();
 
-    io_service->stop();
-    io_service->restart();
-    try {
-        io_service->poll();
-    } catch (...) {
-    }
+    io_service->stopAndPoll();
 
     // There was an error in communication with the partner or the
     // partner was unable to revert its state.
index 122de668dfffd255e02a6cb9e5cbf0112721f0b5..302e1d2c873b3afdfb320be258a7a7229eaed427 100644 (file)
@@ -84,20 +84,10 @@ public:
 
     /// @brief Destructor.
     ~HAImplTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         ha_impl_.reset();
         test_ha_impl_.reset();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         // Clear statistics.
         StatsMgr::instance().removeAll();
     }
@@ -149,19 +139,9 @@ public:
         checkAnswer(response, CONTROL_RESULT_ERROR, expected_response);
         callout_handle.reset();
 
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         ha_impl_.reset();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief HA Instance under test.
index 027900fd27ba0b868c4e53dad5587b2a6b2ff5c4..4344a40afd4bd9af0f4273e39c8ccf0dcf4fb4e3 100644 (file)
@@ -134,12 +134,7 @@ public:
     ///
     /// Stops all test servers.
     ~HAMtServiceTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         MultiThreadingMgr::instance().setMode(false);
         CmdResponseCreator::command_accept_list_.clear();
     }
index ac5f2a5715fb8a43e370b7ae2241955c05d0492c..611b6351cb4954a27f57447cf79dced8331a9a6e 100644 (file)
@@ -625,12 +625,7 @@ public:
         listener_->stop();
         listener2_->stop();
         listener3_->stop();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         MultiThreadingMgr::instance().setMode(false);
         CfgMgr::instance().clear();
     }
@@ -1513,12 +1508,7 @@ public:
         // Change the partner's response to success.
         factory2_->getResponseCreator()->setControlResult(CONTROL_RESULT_SUCCESS);
 
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
 
         // Try sending the lease updates again. The previously rejected lease should
         // now be accepted and the counter should be 0.
@@ -5782,12 +5772,7 @@ public:
     }
 
     ~HAServiceStateMachineTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Creates common HA service instance from the provided configuration.
index f9365d5413c6ec93dfa02142de09c915d0968726..92e95bee1ce67b28677d423b74489c02ffcbe2ca 100644 (file)
@@ -59,12 +59,7 @@ HATest::~HATest() {
     if (timer_) {
         timer_->cancel();
     }
-    io_service_->stop();
-    io_service_->restart();
-    try {
-        io_service_->poll();
-    } catch (...) {
-    }
+    io_service_->stopAndPoll();
 }
 
 void
index a3f5e5bab0accffe69f8ee9c40d7b6e93fad2343..50db009e38b65619ffb5a30958ab454d50b94099 100644 (file)
@@ -69,7 +69,7 @@ int load(LibraryHandle& /* handle */) {
 /// @param handle callout handle passed to the callout.
 /// @return 0 on success, 1 otherwise.
 int dhcp4_srv_configured(CalloutHandle& handle) {
-    isc::dhcp::MySqlConfigBackendImpl::getIOService().reset(new IOService());
+    isc::dhcp::MySqlConfigBackendImpl::setIOService(IOServicePtr(new IOService()));
     IOServiceMgr::instance().registerIOService(isc::dhcp::MySqlConfigBackendImpl::getIOService());
     return (0);
 }
@@ -81,7 +81,7 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
 /// @param handle callout handle passed to the callout.
 /// @return 0 on success, 1 otherwise.
 int dhcp6_srv_configured(CalloutHandle& handle) {
-    isc::dhcp::MySqlConfigBackendImpl::getIOService().reset(new IOService());
+    isc::dhcp::MySqlConfigBackendImpl::setIOService(IOServicePtr(new IOService()));
     IOServiceMgr::instance().registerIOService(isc::dhcp::MySqlConfigBackendImpl::getIOService());
     return (0);
 }
@@ -96,12 +96,7 @@ int unload() {
     isc::dhcp::MySqlConfigBackendDHCPv6::unregisterBackendType();
     IOServiceMgr::instance().unregisterIOService(isc::dhcp::MySqlConfigBackendImpl::getIOService());
     if (isc::dhcp::MySqlConfigBackendImpl::getIOService()) {
-        isc::dhcp::MySqlConfigBackendImpl::getIOService()->stop();
-        isc::dhcp::MySqlConfigBackendImpl::getIOService()->restart();
-        try {
-            isc::dhcp::MySqlConfigBackendImpl::getIOService()->poll();
-        } catch (...) {
-        }
+        isc::dhcp::MySqlConfigBackendImpl::getIOService()->stopAndPoll();
     }
     return (0);
 }
index 03a24ac750e0bf052a134f16cca3150e3995d90d..78dbdb5d5664f3dc174081560ba5b5efdf0baa3a 100644 (file)
@@ -69,7 +69,7 @@ int load(LibraryHandle& /* handle */) {
 /// @param handle callout handle passed to the callout.
 /// @return 0 on success, 1 otherwise.
 int dhcp4_srv_configured(CalloutHandle& handle) {
-    isc::dhcp::PgSqlConfigBackendImpl::getIOService().reset(new IOService());
+    isc::dhcp::PgSqlConfigBackendImpl::setIOService(IOServicePtr(new IOService()));
     IOServiceMgr::instance().registerIOService(isc::dhcp::PgSqlConfigBackendImpl::getIOService());
     return (0);
 }
@@ -81,7 +81,7 @@ int dhcp4_srv_configured(CalloutHandle& handle) {
 /// @param handle callout handle passed to the callout.
 /// @return 0 on success, 1 otherwise.
 int dhcp6_srv_configured(CalloutHandle& handle) {
-    isc::dhcp::PgSqlConfigBackendImpl::getIOService().reset(new IOService());
+    isc::dhcp::PgSqlConfigBackendImpl::setIOService(IOServicePtr(new IOService()));
     IOServiceMgr::instance().registerIOService(isc::dhcp::PgSqlConfigBackendImpl::getIOService());
     return (0);
 }
@@ -96,12 +96,7 @@ int unload() {
     isc::dhcp::PgSqlConfigBackendDHCPv6::unregisterBackendType();
     IOServiceMgr::instance().unregisterIOService(isc::dhcp::PgSqlConfigBackendImpl::getIOService());
     if (isc::dhcp::PgSqlConfigBackendImpl::getIOService()) {
-        isc::dhcp::PgSqlConfigBackendImpl::getIOService()->stop();
-        isc::dhcp::PgSqlConfigBackendImpl::getIOService()->restart();
-        try {
-            isc::dhcp::PgSqlConfigBackendImpl::getIOService()->poll();
-        } catch (...) {
-        }
+        isc::dhcp::PgSqlConfigBackendImpl::getIOService()->stopAndPoll();
     }
     return (0);
 }
index 66dc67ab5ac260dfd3d88b30fb0913ebedce6084..7db3dc66bc37d8b5550dd06b202493968ff6e09d 100644 (file)
@@ -157,12 +157,7 @@ public:
     virtual ~IOFetchTest() {
         shutdown_ = true;
         timer_.cancel();
-        service_->stop();
-        service_->restart();
-        try {
-            service_->poll();
-        } catch (...) {
-        }
+        service_->stopAndPoll();
     }
 
     /// \brief UDP Response handler (the "remote UDP DNS server")
index 99d458a2bcb047612c85ac58efbaca96f5557a28..7735604e2892a7e33dd8804049962b66457eac09 100644 (file)
@@ -179,5 +179,20 @@ IOService::post(const std::function<void ()>& callback) {
     return (io_impl_->post(callback));
 }
 
+void
+IOService::stopAndPoll(bool ignore_errors) {
+    stop();
+    restart();
+    if (ignore_errors) {
+        try {
+            poll();
+        } catch (...) {
+            // Ignore all exceptions.
+        }
+    } else {
+        poll();
+    }
+}
+
 }  // namespace asiolink
 }  // namespace isc
index 14a33767d8d7617f67059aa2d4c99921ff60512c..3173b851aa9a98909ba6eb19d21942a0c115ab1f 100644 (file)
@@ -120,6 +120,11 @@ public:
     /// by small bits that are called from time to time).
     void post(const std::function<void ()>& callback);
 
+    /// @brief Stop and poll to handle all registered events.
+    ///
+    /// @param ignore_errors Flag which indicates if errors should be ignored.
+    void stopAndPoll(bool ignore_errors = true);
+
 private:
 
     /// @brief The implementation.
index 6b8f97c57729321c907be919196cdc56ec2286f8..480a132e9a977336980ce52018e9955ca8f7e72c 100644 (file)
@@ -18,7 +18,13 @@ IOServiceMgr& IOServiceMgr::instance() {
 
 void
 IOServiceMgr::registerIOService(IOServicePtr io_service) {
-    io_services_.push_back(io_service);
+    if (!io_service) {
+        return;
+    }
+    auto it = std::find(io_services_.begin(), io_services_.end(), io_service);
+    if (it == io_services_.end()) {
+        io_services_.push_back(io_service);
+    }
 }
 
 void
index a3b0fb97c27514b1bf2559ec7fdb25d39a4bbe76..3c47d73e48eaebf36bc8034f30891518c5bb18b9 100644 (file)
@@ -16,6 +16,14 @@ namespace asiolink {
 
 class IOServiceMgr;
 
+/// @brief Class which handles events on IOService objects.
+///
+/// Usually hook libraries create a local IOService object which handles events
+/// related to the respective library. To be able to handle these events, the
+/// IOService objects need to be registered on the '[X]_srv_configured' or
+/// on 'load' hook points (before the MT settings are applied).
+/// This class is not thread safe, so all operations must be done on the main
+/// thread, while all other threads are either stopped or paused.
 class IOServiceMgr : boost::noncopyable {
 public:
 
@@ -26,11 +34,18 @@ public:
 
     /// @brief Register IOService.
     ///
+    /// Registering a null IOService does nothing.
+    /// One IOService object can be registered only once, all consecutive calls
+    /// using the same object will be silently ignored.
+    ///
     /// @param io_service The IOService to be registered.
     void registerIOService(IOServicePtr io_service);
 
     /// @brief Unregister IOService.
     ///
+    /// Unregistering an non registered IOService object will be silently
+    /// ignored.
+    ///
     /// @param io_service The IOService to be unregistered.
     void unregisterIOService(IOServicePtr io_service);
 
index 32e0ec7644e9f8b02e690eb70b1eb5436b561f00..b325b110a94e9bf2a316fe516caca2ffb160a13d 100644 (file)
@@ -208,7 +208,7 @@ private:
     /// @param pid the pid to wait for, -1 by default meaning wait
     /// for any child process
     /// @param sync whether this function is called immediately after spawning
-    /// (synchronous) or not (asynchronous, default).
+    /// (synchronous) or not (asynchronous).
     static void waitForProcess(int signum, pid_t const wpid = -1,
                                bool const sync = false);
 
@@ -216,7 +216,7 @@ private:
     static ProcessCollection process_collection_;
 
     /// @brief Whether the process is waited immediately after spawning
-    /// (synchronous) or not (asynchronous, default).
+    /// (synchronous) or not (asynchronous).
     bool sync_;
 
     /// @brief Path to an executable.
index bd9376d5afa3adbd6e9aa72f0b5af52e047e738e..4abfd153212bceec01c3a2e7169a445961f7164f 100644 (file)
@@ -23,12 +23,7 @@ protected:
         timer_cancel_success_(false) {
     }
     ~IntervalTimerTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
     class TimerCallBack {
     public:
index d180f668337db6e274f25257eba28291cd2bdc60..16073aa41e26c0be4563fb27628af128804a7a80 100644 (file)
@@ -14,7 +14,31 @@ using namespace isc::asiolink;
 
 namespace {
 
-TEST(IOServiceMgr, testIOServiceMgr) {
+// Test if IOServiceMgr behaves like a singleton.
+TEST(IOServiceMgr, singleton) {
+    IOServiceMgr& one(IOServiceMgr::instance());
+    IOServiceMgr& two(IOServiceMgr::instance());
+    EXPECT_EQ(&one, &two);
+    EXPECT_FALSE(std::is_copy_constructible<IOServiceMgr>::value);
+}
+
+// Test exceptional cases.
+TEST(IOServiceMgr, noError) {
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+    // Regiter null IOService.
+    ASSERT_NO_THROW(IOServiceMgr::instance().registerIOService(IOServicePtr()));
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+    // Unregister null IOService.
+    ASSERT_NO_THROW(IOServiceMgr::instance().unregisterIOService(IOServicePtr()));
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+    // Unregister not registered IOService.
+    ASSERT_NO_THROW(IOServiceMgr::instance().unregisterIOService(IOServicePtr(new IOService())));
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+}
+
+// Create two IOService objects in a local scope and check that all events
+// already registered are handled after local scope ends.
+TEST(IOServiceMgr, testIOServiceMgrLocalIOServies) {
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
     int one_io_callback_count = 0;
     auto one_f = [&one_io_callback_count] () {
@@ -24,6 +48,7 @@ TEST(IOServiceMgr, testIOServiceMgr) {
     auto two_f = [&two_io_callback_count] () {
         two_io_callback_count++;
     };
+
     {
         IOServicePtr one_io_service(new IOService());
         one_io_service->post(one_f);
@@ -54,6 +79,19 @@ TEST(IOServiceMgr, testIOServiceMgr) {
 
     IOServiceMgr::instance().clearIOServices();
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+}
+
+// Create two IOService objects and test register, unregister and poll.
+TEST(IOServiceMgr, testIOServiceMgrRegisterAndUnregister) {
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
+    int one_io_callback_count = 0;
+    auto one_f = [&one_io_callback_count] () {
+        one_io_callback_count++;
+    };
+    int two_io_callback_count = 0;
+    auto two_f = [&two_io_callback_count] () {
+        two_io_callback_count++;
+    };
 
     IOServicePtr one_io_service(new IOService());
     one_io_service->post(one_f);
@@ -62,15 +100,15 @@ TEST(IOServiceMgr, testIOServiceMgr) {
     two_io_service->post(two_f);
 
     IOServiceMgr::instance().pollIOServices();
-    EXPECT_EQ(one_io_callback_count, 2);
-    EXPECT_EQ(two_io_callback_count, 2);
+    EXPECT_EQ(one_io_callback_count, 0);
+    EXPECT_EQ(two_io_callback_count, 0);
 
     IOServiceMgr::instance().registerIOService(one_io_service);
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 1);
 
     IOServiceMgr::instance().pollIOServices();
-    EXPECT_EQ(one_io_callback_count, 3);
-    EXPECT_EQ(two_io_callback_count, 2);
+    EXPECT_EQ(one_io_callback_count, 1);
+    EXPECT_EQ(two_io_callback_count, 0);
     one_io_service->post(one_f);
     two_io_service->post(two_f);
 
@@ -78,17 +116,20 @@ TEST(IOServiceMgr, testIOServiceMgr) {
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 2);
 
     IOServiceMgr::instance().pollIOServices();
-    EXPECT_EQ(one_io_callback_count, 4);
-    EXPECT_EQ(two_io_callback_count, 4);
+    EXPECT_EQ(one_io_callback_count, 2);
+    EXPECT_EQ(two_io_callback_count, 2);
     one_io_service->post(one_f);
     two_io_service->post(two_f);
 
+    ASSERT_NO_THROW(IOServiceMgr::instance().registerIOService(one_io_service));
+    EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 2);
+
     IOServiceMgr::instance().unregisterIOService(one_io_service);
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 1);
 
     IOServiceMgr::instance().pollIOServices();
-    EXPECT_EQ(one_io_callback_count, 4);
-    EXPECT_EQ(two_io_callback_count, 5);
+    EXPECT_EQ(one_io_callback_count, 2);
+    EXPECT_EQ(two_io_callback_count, 3);
     one_io_service->post(one_f);
     two_io_service->post(two_f);
 
@@ -96,8 +137,8 @@ TEST(IOServiceMgr, testIOServiceMgr) {
     EXPECT_EQ(IOServiceMgr::instance().getIOServiceCount(), 0);
 
     IOServiceMgr::instance().pollIOServices();
-    EXPECT_EQ(one_io_callback_count, 4);
-    EXPECT_EQ(two_io_callback_count, 5);
+    EXPECT_EQ(one_io_callback_count, 2);
+    EXPECT_EQ(two_io_callback_count, 3);
 }
 
 } // namespace
index e7b66888f4666a5b97c7e03976a50e1c41ba7be4..86ffc221f64fde64e7928b597739851fa9e0ee39 100644 (file)
@@ -69,12 +69,7 @@ public:
         io_signal_set_->remove(SIGCHLD);
         io_signal_set_.reset();
         // Make sure the cancel handler for the IOSignalSet is called.
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Method used as the IOSignalSet handler.
index ebee8a371ed79742b13564bfb6640a8b5dacde25..a9d93876f6fa31a5a7917264ecbada9e19f9f627 100644 (file)
@@ -221,12 +221,7 @@ public:
     virtual ~TCPAcceptorTest() {
         running_ = false;
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Specifies how many new connections are expected before the IO
index aa319619fbbb460a13ce737a9706a2597298f371..78889cd4ef98eaf9b5029b4a2d9855b6a584d191 100644 (file)
@@ -228,12 +228,7 @@ public:
     virtual ~TLSAcceptorTest() {
         running_ = false;
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Specifies how many new connections are expected before the IO
index 80eb0b2f7e630a4c3c7e7807e00e6987226c5c6e..cfebf1345cee9d53c7be6adbbd035c10e18a133f 100644 (file)
@@ -421,12 +421,7 @@ public:
 
     /// @brief Destructor.
     virtual ~TLSTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief IO service.
index 37abacd77a3b900c9b88573b6dda9e4041e53b5a..de2d2f89971f28ff00a41a6f8f0c4312286ddfd7 100644 (file)
@@ -48,12 +48,7 @@ public:
     virtual ~UnixDomainSocketTest() {
         removeUnixSocketFile();
         test_socket_.reset();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Returns socket file path.
index a516617d0caa563f3bf684847217dfea572e309a..9dfea59bdf8cdf61fce44abb373ec3402c36ce36 100644 (file)
@@ -92,12 +92,7 @@ CmdHttpListener::start() {
         }
 
         if (thread_io_service_) {
-            thread_io_service_->stop();
-            thread_io_service_->restart();
-            try {
-                thread_io_service_->poll();
-            } catch (...) {
-            }
+            thread_io_service_->stopAndPoll();
             thread_io_service_->stop();
         }
 
@@ -152,12 +147,7 @@ CmdHttpListener::stop() {
     // Stop the listener.
     http_listener_->stop();
 
-    thread_io_service_->stop();
-    thread_io_service_->restart();
-    try {
-        thread_io_service_->poll();
-    } catch (...) {
-    }
+    thread_io_service_->stopAndPoll();
     thread_io_service_->stop();
 
     // Get rid of the thread pool.
index 6e508a6f5c55b5acd2e397bc4a4046ce61d09132..a9301f864c2a136f14c1a38072b1a6c6b945dba4 100644 (file)
@@ -46,12 +46,7 @@ public:
         removeUnixSocketFile();
         conn_.reset();
         test_socket_.reset();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Returns socket file path.
index 8e407583cbc59da13eca31a06570ebc69a3406f9..d878b8e9a447c2c44faf702975e51cbf57d27165 100644 (file)
@@ -81,12 +81,7 @@ public:
         }
 
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
 
         // Deregisters commands.
         config::CommandMgr::instance().deregisterAll();
index 864acc358798288f61d87e0f3c776f0412f1ccdd..ff96dba4491f77e9ad6e4725b2f49426c52fc913 100644 (file)
@@ -127,12 +127,7 @@ public:
     virtual ~DNSClientTest() {
         test_timer_.cancel();
         dns_client_->stop();
-        service_->stop();
-        service_->restart();
-        try {
-            service_->poll();
-        } catch (...) {
-        }
+        service_->stopAndPoll();
         asiodns::logger.setSeverity(isc::log::DEBUG);
     };
 
@@ -451,12 +446,7 @@ public:
         // Since the callback, operator(), calls stop() on the io_service,
         // we must reset it in order for subsequent calls to run() or
         // runOne() to work.
-        service_->stop();
-        service_->restart();
-        try {
-            service_->poll();
-        } catch (...) {
-        }
+        service_->stopAndPoll();
     }
 
     /// @brief Performs a single request-response exchange with or without TSIG.
@@ -508,12 +498,7 @@ public:
         // Since the callback, operator(), calls stop() on the io_service,
         // we must reset it in order for subsequent calls to run() or
         // runOne() to work.
-        service_->stop();
-        service_->restart();
-        try {
-            service_->poll();
-        } catch (...) {
-        }
+        service_->stopAndPoll();
     }
 };
 
index 39e024f39a02010c862ff97499dce762c8b1009b..adc87328eb82a74a2cd5151b7df180b445fbccc0 100644 (file)
@@ -279,12 +279,7 @@ public:
 
     virtual ~NameChangeTransactionTest() {
         timer_->cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         io_service_.reset(new IOService());
         timer_.reset(new IntervalTimer(io_service_));
     }
index 563b5ba69e2d7a7bf4c7a277c13b03faf399bc04..436689c4cd9a81e7622e8331096279aa76fb40af 100644 (file)
@@ -227,12 +227,7 @@ TimedIO::TimedIO()
 
 TimedIO::~TimedIO() {
     timer_->cancel();
-    io_service_->stop();
-    io_service_->restart();
-    try {
-        io_service_->poll();
-    } catch (...) {
-    }
+    io_service_->stopAndPoll();
 }
 
 int
index 109fa8874ffbafd6a8418ab851d7454bf4681174..a629d1d0865a870b2bb126c6ed54e232ef5bae32 100644 (file)
@@ -231,9 +231,7 @@ NameChangeSender::stopSending() {
 
     if (io_service_) {
         try {
-            io_service_->stop();
-            io_service_->restart();
-            io_service_->poll();
+            io_service_->stopAndPoll(false);
         } catch (const std::exception& ex) {
             // Swallow exceptions. If we have some sort of error we'll log
             // it but we won't propagate the throw.
index 904af5b9195043609e352294b56261f9a8ea1695..46023911f311fb9c23f9536d7d1aa6b3c8497e37 100644 (file)
@@ -202,12 +202,7 @@ public:
 
     virtual ~NameChangeUDPListenerTest() {
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Converts JSON string into an NCR and sends it to the listener.
@@ -1038,12 +1033,7 @@ public:
 
     ~NameChangeUDPTest() {
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         // Disable multi-threading
         MultiThreadingMgr::instance().setMode(false);
     }
index a1068d42d5bede2f79c941e22e4f590dff02e20f..6b5e4a4e4ec30ee97321e8b01f380971b078ea1a 100644 (file)
@@ -314,12 +314,7 @@ D2ClientMgr::stopSender() {
     }
 
     if (private_io_service_) {
-        private_io_service_->stop();
-        private_io_service_->restart();
-        try {
-            private_io_service_->poll();
-        } catch (...) {
-        }
+        private_io_service_->stopAndPoll();
     }
 }
 
index d37f0c162008ad461592050ddc90200e7c4b467e..d4d697d929b4af226b1982f1b1195cf16d453e3d 100644 (file)
@@ -310,12 +310,7 @@ public:
     /// timers.
     virtual ~CfgExpirationTimersTest() {
         cleanupTimerMgr();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Stop @c TimerMgr worker thread and remove the timers.
index ecec43ddaa1cb337f622cab732ae4694bc81f339..470d683272306955b8ba0bcbe6caa81a3fa7f6ce 100644 (file)
@@ -166,12 +166,7 @@ public:
         // Disable multi-threading.
         MultiThreadingMgr::instance().setMode(false);
 
-        getIOService()->stop();
-        getIOService()->restart();
-        try {
-            getIOService()->poll();
-        } catch(...) {
-        }
+        getIOService()->stopAndPoll();
     }
 
     /// @brief Remove files being products of Lease File Cleanup.
index 284ca8c199e59ccbeaa546cbfb6e4d95eac05587..5900a857ddfe0db8e2a7b2c8781c5326af942d8c 100644 (file)
@@ -147,12 +147,7 @@ void
 TimerMgrTest::TearDown() {
     // Remove all timers.
     timer_mgr_->unregisterTimers();
-    io_service_->stop();
-    io_service_->restart();
-    try {
-        io_service_->poll();
-    } catch (...) {
-    }
+    io_service_->stopAndPoll();
 }
 
 void
index 20ccbc4966d1f9533704ce186a2a5c1fd9754c0f..380508e13199b163d8833cf16a702e88eb7e764e 100644 (file)
@@ -1847,12 +1847,7 @@ public:
         }
 
         if (thread_io_service_) {
-            thread_io_service_->stop();
-            thread_io_service_->restart();
-            try {
-                thread_io_service_->poll();
-            } catch (...) {
-            }
+            thread_io_service_->stopAndPoll();
             thread_io_service_->stop();
         }
     }
index 73c09d4636137fb1704841a0e890f12f2640e9ff..c975b604868016508e9f0bb7c3a8385d9672e613 100644 (file)
@@ -218,12 +218,7 @@ public:
         }
 
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
 
         MultiThreadingMgr::instance().setMode(false);
     }
index ac0fac5bda367c2e8cca14b39c9f46fed046e86f..c6e72585419b786ffffbd321a4c03891e8f5bc7a 100644 (file)
@@ -114,12 +114,7 @@ public:
 
     /// @brief Destructor.
     ~HttpConnectionPoolTest() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
         MultiThreadingMgr::instance().setMode(false);
     }
 
index 62cd2f97179827d021a22fc27741083da8a2b001..4b71b259fbe58ace7698c79eeffb3410e2abde7d 100644 (file)
@@ -413,12 +413,7 @@ public:
             client->close();
         }
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Connect to the endpoint.
@@ -459,9 +454,7 @@ public:
                                         timeout, IntervalTimer::ONE_SHOT);
         }
         io_service_->run();
-        io_service_->stop();
-        io_service_->restart();
-        io_service_->poll();
+        io_service_->stopAndPoll(false);
     }
 
     /// @brief Returns HTTP OK response expected by unit tests.
@@ -1030,12 +1023,7 @@ public:
         listener_.stop();
         listener2_.stop();
         listener3_.stop();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch(...) {
-        }
+        io_service_->stopAndPoll();
         MultiThreadingMgr::instance().setMode(false);
     }
 
index dcba531ee46d569f9ac9098390a50ab1a16fa179..5135d9256c88b2780f0e9bcb6e39d96eea8f2d49 100644 (file)
@@ -236,12 +236,7 @@ public:
     /// @brief Destructor.
     virtual ~HttpListenerTest() {
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Callback function invoke upon test timeout.
@@ -270,9 +265,7 @@ public:
                                         timeout, IntervalTimer::ONE_SHOT);
         }
         io_service_->run();
-        io_service_->stop();
-        io_service_->restart();
-        io_service_->poll();
+        io_service_->stopAndPoll(false);
     }
 
     /// @brief IO service used in the tests.
index 6984caa9aeae8c926937d4f2e708796daade241c..18aba1d1555344a36bede781b7fa12674a59410f 100644 (file)
@@ -652,12 +652,7 @@ public:
             client->close();
         }
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Connect to the endpoint.
@@ -699,9 +694,7 @@ public:
                                         timeout, IntervalTimer::ONE_SHOT);
         }
         io_service_->run();
-        io_service_->stop();
-        io_service_->restart();
-        io_service_->poll();
+        io_service_->stopAndPoll(false);
     }
 
     /// @brief Returns HTTP OK response expected by unit tests.
index 8926379db235769b03920fbf84650b58e006f304..e8775543157c786d55d27c2abb1cabe3d44a1527 100644 (file)
@@ -146,12 +146,7 @@ public:
 
     /// @brief Destructor
     virtual ~DProcessBase() {
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Checks if the process has been instructed to shut down.
index 5b71d622d1b971dc18ce2071d5fc89840a197cda..e880284bde4661f5c00ead4dbf6e1a7c89222546 100644 (file)
@@ -88,12 +88,7 @@ MtTcpListenerMgr::start() {
         }
 
         if (thread_io_service_) {
-            thread_io_service_->stop();
-            thread_io_service_->restart();
-            try {
-                thread_io_service_->poll();
-            } catch (...) {
-            }
+            thread_io_service_->stopAndPoll();
             thread_io_service_->stop();
         }
 
@@ -139,8 +134,8 @@ MtTcpListenerMgr::stop() {
     }
 
     LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_BASIC, MT_TCP_LISTENER_MGR_STOPPING)
-              .arg(address_)
-              .arg(port_);
+        .arg(address_)
+        .arg(port_);
 
     // Stop the thread pool.
     thread_pool_->stop();
@@ -148,12 +143,7 @@ MtTcpListenerMgr::stop() {
     // Stop the listener.
     tcp_listener_->stop();
 
-    thread_io_service_->stop();
-    thread_io_service_->restart();
-    try {
-        thread_io_service_->poll();
-    } catch (...) {
-    }
+    thread_io_service_->stopAndPoll();
     thread_io_service_->stop();
 
     // Get rid of the thread pool.
@@ -166,8 +156,8 @@ MtTcpListenerMgr::stop() {
     thread_io_service_.reset();
 
     LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_BASIC, MT_TCP_LISTENER_MGR_STOPPED)
-              .arg(address_)
-              .arg(port_);
+        .arg(address_)
+        .arg(port_);
 }
 
 bool
index 58c394afe707def887cdd3577d18484b3d3f1a1a..ad8ecea4c9a1b69a2979bba77d251d1eec3bf3ef 100644 (file)
@@ -75,12 +75,7 @@ public:
         }
 
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
 
         // Disable multi-threading.
         MultiThreadingMgr::instance().setMode(false);
index 92bfe8f7ea090def5ab722f3c3577163c234995b..9d10e7478ad61150eb9b93a2d37bdf2aaca19718 100644 (file)
@@ -71,12 +71,7 @@ public:
         }
 
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Create a new client.
@@ -158,9 +153,7 @@ public:
                                         IntervalTimer::ONE_SHOT);
         }
         io_service_->run();
-        io_service_->stop();
-        io_service_->restart();
-        io_service_->poll();
+        io_service_->stopAndPoll(false);
     }
 
     /// @brief Filter that denies every other connection.
index 9d1714117fc8815e2a808ef0993bbe2ac08e532f..b5c4e7c50202a64520290e83c8b6a3cd5a527ed1 100644 (file)
@@ -66,12 +66,7 @@ public:
         }
 
         test_timer_.cancel();
-        io_service_->stop();
-        io_service_->restart();
-        try {
-            io_service_->poll();
-        } catch (...) {
-        }
+        io_service_->stopAndPoll();
     }
 
     /// @brief Fetch the server TLS context.
@@ -168,9 +163,7 @@ public:
                                         IntervalTimer::ONE_SHOT);
         }
         io_service_->run();
-        io_service_->stop();
-        io_service_->restart();
-        io_service_->poll();
+        io_service_->stopAndPoll(false);
     }
 
     /// @brief Filter that denies every other connection.