diff options
author | Razvan Becheriu <razvan@isc.org> | 2024-04-22 19:46:43 +0200 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-04-22 22:00:29 +0200 |
commit | a0707133f8b58ea05efd34eab8d9b975b37bf7ae (patch) | |
tree | 2c5c31cff069febdcb232be487429795fd523334 /src/hooks | |
parent | [#3315] fix ProcessSpawn IOService (diff) | |
download | kea-a0707133f8b58ea05efd34eab8d9b975b37bf7ae.tar.xz kea-a0707133f8b58ea05efd34eab8d9b975b37bf7ae.zip |
[#3315] use stopAndPoll
Diffstat (limited to 'src/hooks')
-rw-r--r-- | src/hooks/dhcp/high_availability/ha.dox | 5 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/ha_callouts.cc | 7 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/ha_service.cc | 35 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/tests/ha_impl_unittest.cc | 28 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/tests/ha_mt_unittest.cc | 7 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc | 21 | ||||
-rw-r--r-- | src/hooks/dhcp/high_availability/tests/ha_test.cc | 7 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_callouts.cc | 11 | ||||
-rw-r--r-- | src/hooks/dhcp/pgsql_cb/pgsql_cb_callouts.cc | 11 |
9 files changed, 24 insertions, 108 deletions
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); } |