summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRazvan Becheriu <razvan@isc.org>2024-04-22 19:46:43 +0200
committerRazvan Becheriu <razvan@isc.org>2024-04-22 22:00:29 +0200
commita0707133f8b58ea05efd34eab8d9b975b37bf7ae (patch)
tree2c5c31cff069febdcb232be487429795fd523334
parent[#3315] fix ProcessSpawn IOService (diff)
downloadkea-a0707133f8b58ea05efd34eab8d9b975b37bf7ae.tar.xz
kea-a0707133f8b58ea05efd34eab8d9b975b37bf7ae.zip
[#3315] use stopAndPoll
-rw-r--r--src/bin/agent/ca_process.cc4
-rw-r--r--src/bin/agent/tests/ca_command_mgr_unittests.cc8
-rw-r--r--src/bin/agent/tests/ca_process_unittests.cc7
-rw-r--r--src/bin/d2/d2_hooks.dox2
-rw-r--r--src/bin/d2/d2_process.cc11
-rw-r--r--src/bin/d2/tests/d2_process_unittests.cc14
-rw-r--r--src/bin/d2/tests/d2_queue_mgr_unittests.cc7
-rw-r--r--src/bin/d2/tests/d2_update_mgr_unittests.cc7
-rw-r--r--src/bin/dhcp4/ctrl_dhcp4_srv.cc3
-rw-r--r--src/bin/dhcp4/dhcp4_hooks.dox2
-rw-r--r--src/bin/dhcp4/dhcp4_srv.cc8
-rw-r--r--src/bin/dhcp4/json_config_parser.cc3
-rw-r--r--src/bin/dhcp6/ctrl_dhcp6_srv.cc3
-rw-r--r--src/bin/dhcp6/dhcp6_hooks.dox2
-rw-r--r--src/bin/dhcp6/dhcp6_srv.cc8
-rw-r--r--src/bin/dhcp6/json_config_parser.cc3
-rw-r--r--src/bin/dhcp6/tests/dhcp6_process_tests.sh.in2
-rw-r--r--src/bin/dhcp6/tests/dhcp6_test_utils.h7
-rw-r--r--src/bin/netconf/http_control_socket.cc7
-rw-r--r--src/bin/netconf/netconf_process.cc4
-rw-r--r--src/bin/netconf/tests/control_socket_unittests.cc14
-rw-r--r--src/bin/netconf/tests/netconf_process_unittests.cc7
-rw-r--r--src/bin/netconf/tests/netconf_unittests.cc7
-rw-r--r--src/hooks/dhcp/high_availability/ha.dox5
-rw-r--r--src/hooks/dhcp/high_availability/ha_callouts.cc7
-rw-r--r--src/hooks/dhcp/high_availability/ha_service.cc35
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc28
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc7
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc21
-rw-r--r--src/hooks/dhcp/high_availability/tests/ha_test.cc7
-rw-r--r--src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc11
-rw-r--r--src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc11
-rw-r--r--src/lib/asiodns/tests/io_fetch_unittest.cc7
-rw-r--r--src/lib/asiolink/io_service.cc15
-rw-r--r--src/lib/asiolink/io_service.h5
-rw-r--r--src/lib/asiolink/io_service_mgr.cc8
-rw-r--r--src/lib/asiolink/io_service_mgr.h15
-rw-r--r--src/lib/asiolink/process_spawn.cc4
-rw-r--r--src/lib/asiolink/tests/interval_timer_unittest.cc7
-rw-r--r--src/lib/asiolink/tests/io_service_mgr_unittest.cc63
-rw-r--r--src/lib/asiolink/tests/process_spawn_unittest.cc7
-rw-r--r--src/lib/asiolink/tests/tcp_acceptor_unittest.cc7
-rw-r--r--src/lib/asiolink/tests/tls_acceptor_unittest.cc7
-rw-r--r--src/lib/asiolink/tests/tls_unittest.cc7
-rw-r--r--src/lib/asiolink/tests/unix_domain_socket_unittest.cc7
-rw-r--r--src/lib/config/cmd_http_listener.cc14
-rw-r--r--src/lib/config/tests/client_connection_unittests.cc7
-rw-r--r--src/lib/config/tests/cmd_http_listener_unittests.cc7
-rw-r--r--src/lib/d2srv/tests/dns_client_unittests.cc21
-rw-r--r--src/lib/d2srv/tests/nc_trans_unittests.cc7
-rw-r--r--src/lib/d2srv/testutils/nc_test_utils.cc7
-rw-r--r--src/lib/dhcp_ddns/ncr_io.cc4
-rw-r--r--src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc14
-rw-r--r--src/lib/dhcpsrv/d2_client_mgr.cc7
-rw-r--r--src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc7
-rw-r--r--src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc7
-rw-r--r--src/lib/dhcpsrv/tests/timer_mgr_unittest.cc7
-rw-r--r--src/lib/http/client.cc7
-rw-r--r--src/lib/http/tests/client_mt_unittests.cc7
-rw-r--r--src/lib/http/tests/connection_pool_unittests.cc7
-rw-r--r--src/lib/http/tests/server_client_unittests.cc18
-rw-r--r--src/lib/http/tests/tls_client_unittests.cc11
-rw-r--r--src/lib/http/tests/tls_server_unittests.cc11
-rw-r--r--src/lib/process/d_process.h7
-rw-r--r--src/lib/tcp/mt_tcp_listener_mgr.cc22
-rw-r--r--src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc7
-rw-r--r--src/lib/tcp/tests/tcp_listener_unittests.cc11
-rw-r--r--src/lib/tcp/tests/tls_listener_unittests.cc11
68 files changed, 204 insertions, 455 deletions
diff --git a/src/bin/agent/ca_process.cc b/src/bin/agent/ca_process.cc
index 2bfa6a77b6..2403eedb1a 100644
--- a/src/bin/agent/ca_process.cc
+++ b/src/bin/agent/ca_process.cc
@@ -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;
diff --git a/src/bin/agent/tests/ca_command_mgr_unittests.cc b/src/bin/agent/tests/ca_command_mgr_unittests.cc
index bd25e58cbf..4cef0426cd 100644
--- a/src/bin/agent/tests/ca_command_mgr_unittests.cc
+++ b/src/bin/agent/tests/ca_command_mgr_unittests.cc
@@ -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
diff --git a/src/bin/agent/tests/ca_process_unittests.cc b/src/bin/agent/tests/ca_process_unittests.cc
index 15b414e4b7..67f4aa0f57 100644
--- a/src/bin/agent/tests/ca_process_unittests.cc
+++ b/src/bin/agent/tests/ca_process_unittests.cc
@@ -86,12 +86,7 @@ TEST_F(CtrlAgentProcessTest, shutdown) {
elapsed.total_milliseconds() <= 400);
timer.cancel();
- getIOService()->stop();
- getIOService()->restart();
- try {
- getIOService()->poll();
- } catch (...) {
- }
+ getIOService()->stopAndPoll();
}
}
diff --git a/src/bin/d2/d2_hooks.dox b/src/bin/d2/d2_hooks.dox
index a01525b5d4..9fe8ebbc0a 100644
--- a/src/bin/d2/d2_hooks.dox
+++ b/src/bin/d2/d2_hooks.dox
@@ -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
diff --git a/src/bin/d2/d2_process.cc b/src/bin/d2/d2_process.cc
index 1e741697e9..75d0704551 100644
--- a/src/bin/d2/d2_process.cc
+++ b/src/bin/d2/d2_process.cc
@@ -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();
}
diff --git a/src/bin/d2/tests/d2_process_unittests.cc b/src/bin/d2/tests/d2_process_unittests.cc
index 83ae400129..b4fb7ae907 100644
--- a/src/bin/d2/tests/d2_process_unittests.cc
+++ b/src/bin/d2/tests/d2_process_unittests.cc
@@ -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
diff --git a/src/bin/d2/tests/d2_queue_mgr_unittests.cc b/src/bin/d2/tests/d2_queue_mgr_unittests.cc
index 16d9998567..97a21d88a6 100644
--- a/src/bin/d2/tests/d2_queue_mgr_unittests.cc
+++ b/src/bin/d2/tests/d2_queue_mgr_unittests.cc
@@ -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();
}
diff --git a/src/bin/d2/tests/d2_update_mgr_unittests.cc b/src/bin/d2/tests/d2_update_mgr_unittests.cc
index 71ba0fb277..0c0262285f 100644
--- a/src/bin/d2/tests/d2_update_mgr_unittests.cc
+++ b/src/bin/d2/tests/d2_update_mgr_unittests.cc
@@ -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.
diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
index 2e8af5434c..aecc2c6d7c 100644
--- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc
+++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc
@@ -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;
diff --git a/src/bin/dhcp4/dhcp4_hooks.dox b/src/bin/dhcp4/dhcp4_hooks.dox
index cb8c699a20..45bc9db30a 100644
--- a/src/bin/dhcp4/dhcp4_hooks.dox
+++ b/src/bin/dhcp4/dhcp4_hooks.dox
@@ -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
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 14ab46a1df..be0e78c532 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -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) {
diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc
index 9ab0c886c5..0b1b7e2e3b 100644
--- a/src/bin/dhcp4/json_config_parser.cc
+++ b/src/bin/dhcp4/json_config_parser.cc
@@ -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;
diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc
index 35dbe1e043..b8314843d8 100644
--- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc
+++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc
@@ -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;
diff --git a/src/bin/dhcp6/dhcp6_hooks.dox b/src/bin/dhcp6/dhcp6_hooks.dox
index d2b3087950..862db7f4e4 100644
--- a/src/bin/dhcp6/dhcp6_hooks.dox
+++ b/src/bin/dhcp6/dhcp6_hooks.dox
@@ -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
diff --git a/src/bin/dhcp6/dhcp6_srv.cc b/src/bin/dhcp6/dhcp6_srv.cc
index 205bf5d23d..49fe1a1865 100644
--- a/src/bin/dhcp6/dhcp6_srv.cc
+++ b/src/bin/dhcp6/dhcp6_srv.cc
@@ -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) {
diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc
index 8de3907438..7783f4142e 100644
--- a/src/bin/dhcp6/json_config_parser.cc
+++ b/src/bin/dhcp6/json_config_parser.cc
@@ -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;
diff --git a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
index ad747214b9..3e2c5550da 100644
--- a/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
+++ b/src/bin/dhcp6/tests/dhcp6_process_tests.sh.in
@@ -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\":
diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.h b/src/bin/dhcp6/tests/dhcp6_test_utils.h
index e519a6e267..ddcd64a8a2 100644
--- a/src/bin/dhcp6/tests/dhcp6_test_utils.h
+++ b/src/bin/dhcp6/tests/dhcp6_test_utils.h
@@ -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.
diff --git a/src/bin/netconf/http_control_socket.cc b/src/bin/netconf/http_control_socket.cc
index aa69a5054e..12b240232f 100644
--- a/src/bin/netconf/http_control_socket.cc
+++ b/src/bin/netconf/http_control_socket.cc
@@ -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.
diff --git a/src/bin/netconf/netconf_process.cc b/src/bin/netconf/netconf_process.cc
index 2e86a9bee0..2d97510302 100644
--- a/src/bin/netconf/netconf_process.cc
+++ b/src/bin/netconf/netconf_process.cc
@@ -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;
diff --git a/src/bin/netconf/tests/control_socket_unittests.cc b/src/bin/netconf/tests/control_socket_unittests.cc
index f9f74f7a67..5f211cf8e5 100644
--- a/src/bin/netconf/tests/control_socket_unittests.cc
+++ b/src/bin/netconf/tests/control_socket_unittests.cc
@@ -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();
}
diff --git a/src/bin/netconf/tests/netconf_process_unittests.cc b/src/bin/netconf/tests/netconf_process_unittests.cc
index 563dc3df50..7746806e8f 100644
--- a/src/bin/netconf/tests/netconf_process_unittests.cc
+++ b/src/bin/netconf/tests/netconf_process_unittests.cc
@@ -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();
}
}
diff --git a/src/bin/netconf/tests/netconf_unittests.cc b/src/bin/netconf/tests/netconf_unittests.cc
index 2efc99f74e..448453cd63 100644
--- a/src/bin/netconf/tests/netconf_unittests.cc
+++ b/src/bin/netconf/tests/netconf_unittests.cc
@@ -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.
diff --git a/src/hooks/dhcp/high_availability/ha.dox b/src/hooks/dhcp/high_availability/ha.dox
index 2ac714f987..66f5402e23 100644
--- a/src/hooks/dhcp/high_availability/ha.dox
+++ b/src/hooks/dhcp/high_availability/ha.dox
@@ -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) {
diff --git a/src/hooks/dhcp/high_availability/ha_callouts.cc b/src/hooks/dhcp/high_availability/ha_callouts.cc
index 014080f8e8..2e4410983b 100644
--- a/src/hooks/dhcp/high_availability/ha_callouts.cc
+++ b/src/hooks/dhcp/high_availability/ha_callouts.cc
@@ -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);
diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc
index 1dfa8f322b..997ae1311a 100644
--- a/src/hooks/dhcp/high_availability/ha_service.cc
+++ b/src/hooks/dhcp/high_availability/ha_service.cc
@@ -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.
diff --git a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
index 122de668df..302e1d2c87 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc
@@ -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.
diff --git a/src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc
index 027900fd27..4344a40afd 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc
@@ -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();
}
diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
index ac5f2a5715..611b6351cb 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
@@ -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.
diff --git a/src/hooks/dhcp/high_availability/tests/ha_test.cc b/src/hooks/dhcp/high_availability/tests/ha_test.cc
index f9365d5413..92e95bee1c 100644
--- a/src/hooks/dhcp/high_availability/tests/ha_test.cc
+++ b/src/hooks/dhcp/high_availability/tests/ha_test.cc
@@ -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
diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc
index a3f5e5bab0..50db009e38 100644
--- a/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc
+++ b/src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc
@@ -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);
}
diff --git a/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc b/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc
index 03a24ac750..78dbdb5d56 100644
--- a/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc
+++ b/src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc
@@ -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);
}
diff --git a/src/lib/asiodns/tests/io_fetch_unittest.cc b/src/lib/asiodns/tests/io_fetch_unittest.cc
index 66dc67ab5a..7db3dc66bc 100644
--- a/src/lib/asiodns/tests/io_fetch_unittest.cc
+++ b/src/lib/asiodns/tests/io_fetch_unittest.cc
@@ -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")
diff --git a/src/lib/asiolink/io_service.cc b/src/lib/asiolink/io_service.cc
index 99d458a2bc..7735604e28 100644
--- a/src/lib/asiolink/io_service.cc
+++ b/src/lib/asiolink/io_service.cc
@@ -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
diff --git a/src/lib/asiolink/io_service.h b/src/lib/asiolink/io_service.h
index 14a33767d8..3173b851aa 100644
--- a/src/lib/asiolink/io_service.h
+++ b/src/lib/asiolink/io_service.h
@@ -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.
diff --git a/src/lib/asiolink/io_service_mgr.cc b/src/lib/asiolink/io_service_mgr.cc
index 6b8f97c577..480a132e9a 100644
--- a/src/lib/asiolink/io_service_mgr.cc
+++ b/src/lib/asiolink/io_service_mgr.cc
@@ -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
diff --git a/src/lib/asiolink/io_service_mgr.h b/src/lib/asiolink/io_service_mgr.h
index a3b0fb97c2..3c47d73e48 100644
--- a/src/lib/asiolink/io_service_mgr.h
+++ b/src/lib/asiolink/io_service_mgr.h
@@ -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);
diff --git a/src/lib/asiolink/process_spawn.cc b/src/lib/asiolink/process_spawn.cc
index 32e0ec7644..b325b110a9 100644
--- a/src/lib/asiolink/process_spawn.cc
+++ b/src/lib/asiolink/process_spawn.cc
@@ -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.
diff --git a/src/lib/asiolink/tests/interval_timer_unittest.cc b/src/lib/asiolink/tests/interval_timer_unittest.cc
index bd9376d5af..4abfd15321 100644
--- a/src/lib/asiolink/tests/interval_timer_unittest.cc
+++ b/src/lib/asiolink/tests/interval_timer_unittest.cc
@@ -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:
diff --git a/src/lib/asiolink/tests/io_service_mgr_unittest.cc b/src/lib/asiolink/tests/io_service_mgr_unittest.cc
index d180f66833..16073aa41e 100644
--- a/src/lib/asiolink/tests/io_service_mgr_unittest.cc
+++ b/src/lib/asiolink/tests/io_service_mgr_unittest.cc
@@ -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
diff --git a/src/lib/asiolink/tests/process_spawn_unittest.cc b/src/lib/asiolink/tests/process_spawn_unittest.cc
index e7b66888f4..86ffc221f6 100644
--- a/src/lib/asiolink/tests/process_spawn_unittest.cc
+++ b/src/lib/asiolink/tests/process_spawn_unittest.cc
@@ -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.
diff --git a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
index ebee8a371e..a9d93876f6 100644
--- a/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
+++ b/src/lib/asiolink/tests/tcp_acceptor_unittest.cc
@@ -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
diff --git a/src/lib/asiolink/tests/tls_acceptor_unittest.cc b/src/lib/asiolink/tests/tls_acceptor_unittest.cc
index aa319619fb..78889cd4ef 100644
--- a/src/lib/asiolink/tests/tls_acceptor_unittest.cc
+++ b/src/lib/asiolink/tests/tls_acceptor_unittest.cc
@@ -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
diff --git a/src/lib/asiolink/tests/tls_unittest.cc b/src/lib/asiolink/tests/tls_unittest.cc
index 80eb0b2f7e..cfebf1345c 100644
--- a/src/lib/asiolink/tests/tls_unittest.cc
+++ b/src/lib/asiolink/tests/tls_unittest.cc
@@ -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.
diff --git a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
index 37abacd77a..de2d2f8997 100644
--- a/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
+++ b/src/lib/asiolink/tests/unix_domain_socket_unittest.cc
@@ -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.
diff --git a/src/lib/config/cmd_http_listener.cc b/src/lib/config/cmd_http_listener.cc
index a516617d0c..9dfea59bdf 100644
--- a/src/lib/config/cmd_http_listener.cc
+++ b/src/lib/config/cmd_http_listener.cc
@@ -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.
diff --git a/src/lib/config/tests/client_connection_unittests.cc b/src/lib/config/tests/client_connection_unittests.cc
index 6e508a6f5c..a9301f864c 100644
--- a/src/lib/config/tests/client_connection_unittests.cc
+++ b/src/lib/config/tests/client_connection_unittests.cc
@@ -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.
diff --git a/src/lib/config/tests/cmd_http_listener_unittests.cc b/src/lib/config/tests/cmd_http_listener_unittests.cc
index 8e407583cb..d878b8e9a4 100644
--- a/src/lib/config/tests/cmd_http_listener_unittests.cc
+++ b/src/lib/config/tests/cmd_http_listener_unittests.cc
@@ -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();
diff --git a/src/lib/d2srv/tests/dns_client_unittests.cc b/src/lib/d2srv/tests/dns_client_unittests.cc
index 864acc3587..ff96dba449 100644
--- a/src/lib/d2srv/tests/dns_client_unittests.cc
+++ b/src/lib/d2srv/tests/dns_client_unittests.cc
@@ -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();
}
};
diff --git a/src/lib/d2srv/tests/nc_trans_unittests.cc b/src/lib/d2srv/tests/nc_trans_unittests.cc
index 39e024f39a..adc87328eb 100644
--- a/src/lib/d2srv/tests/nc_trans_unittests.cc
+++ b/src/lib/d2srv/tests/nc_trans_unittests.cc
@@ -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_));
}
diff --git a/src/lib/d2srv/testutils/nc_test_utils.cc b/src/lib/d2srv/testutils/nc_test_utils.cc
index 563b5ba69e..436689c4cd 100644
--- a/src/lib/d2srv/testutils/nc_test_utils.cc
+++ b/src/lib/d2srv/testutils/nc_test_utils.cc
@@ -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
diff --git a/src/lib/dhcp_ddns/ncr_io.cc b/src/lib/dhcp_ddns/ncr_io.cc
index 109fa8874f..a629d1d086 100644
--- a/src/lib/dhcp_ddns/ncr_io.cc
+++ b/src/lib/dhcp_ddns/ncr_io.cc
@@ -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.
diff --git a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
index 904af5b919..46023911f3 100644
--- a/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
+++ b/src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
@@ -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);
}
diff --git a/src/lib/dhcpsrv/d2_client_mgr.cc b/src/lib/dhcpsrv/d2_client_mgr.cc
index a1068d42d5..6b5e4a4e4e 100644
--- a/src/lib/dhcpsrv/d2_client_mgr.cc
+++ b/src/lib/dhcpsrv/d2_client_mgr.cc
@@ -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();
}
}
diff --git a/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc b/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
index d37f0c1620..d4d697d929 100644
--- a/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
+++ b/src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
@@ -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.
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
index ecec43ddaa..470d683272 100644
--- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
@@ -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.
diff --git a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
index 284ca8c199..5900a857dd 100644
--- a/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
@@ -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
diff --git a/src/lib/http/client.cc b/src/lib/http/client.cc
index 20ccbc4966..380508e131 100644
--- a/src/lib/http/client.cc
+++ b/src/lib/http/client.cc
@@ -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();
}
}
diff --git a/src/lib/http/tests/client_mt_unittests.cc b/src/lib/http/tests/client_mt_unittests.cc
index 73c09d4636..c975b60486 100644
--- a/src/lib/http/tests/client_mt_unittests.cc
+++ b/src/lib/http/tests/client_mt_unittests.cc
@@ -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);
}
diff --git a/src/lib/http/tests/connection_pool_unittests.cc b/src/lib/http/tests/connection_pool_unittests.cc
index ac0fac5bda..c6e7258541 100644
--- a/src/lib/http/tests/connection_pool_unittests.cc
+++ b/src/lib/http/tests/connection_pool_unittests.cc
@@ -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);
}
diff --git a/src/lib/http/tests/server_client_unittests.cc b/src/lib/http/tests/server_client_unittests.cc
index 62cd2f9717..4b71b259fb 100644
--- a/src/lib/http/tests/server_client_unittests.cc
+++ b/src/lib/http/tests/server_client_unittests.cc
@@ -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);
}
diff --git a/src/lib/http/tests/tls_client_unittests.cc b/src/lib/http/tests/tls_client_unittests.cc
index dcba531ee4..5135d9256c 100644
--- a/src/lib/http/tests/tls_client_unittests.cc
+++ b/src/lib/http/tests/tls_client_unittests.cc
@@ -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.
diff --git a/src/lib/http/tests/tls_server_unittests.cc b/src/lib/http/tests/tls_server_unittests.cc
index 6984caa9ae..18aba1d155 100644
--- a/src/lib/http/tests/tls_server_unittests.cc
+++ b/src/lib/http/tests/tls_server_unittests.cc
@@ -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.
diff --git a/src/lib/process/d_process.h b/src/lib/process/d_process.h
index 8926379db2..e877554315 100644
--- a/src/lib/process/d_process.h
+++ b/src/lib/process/d_process.h
@@ -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.
diff --git a/src/lib/tcp/mt_tcp_listener_mgr.cc b/src/lib/tcp/mt_tcp_listener_mgr.cc
index 5b71d622d1..e880284bde 100644
--- a/src/lib/tcp/mt_tcp_listener_mgr.cc
+++ b/src/lib/tcp/mt_tcp_listener_mgr.cc
@@ -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
diff --git a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
index 58c394afe7..ad8ecea4c9 100644
--- a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
+++ b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
@@ -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);
diff --git a/src/lib/tcp/tests/tcp_listener_unittests.cc b/src/lib/tcp/tests/tcp_listener_unittests.cc
index 92bfe8f7ea..9d10e7478a 100644
--- a/src/lib/tcp/tests/tcp_listener_unittests.cc
+++ b/src/lib/tcp/tests/tcp_listener_unittests.cc
@@ -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.
diff --git a/src/lib/tcp/tests/tls_listener_unittests.cc b/src/lib/tcp/tests/tls_listener_unittests.cc
index 9d1714117f..b5c4e7c502 100644
--- a/src/lib/tcp/tests/tls_listener_unittests.cc
+++ b/src/lib/tcp/tests/tls_listener_unittests.cc
@@ -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.