Skip to content

Commit a070713

Browse files
author
Razvan Becheriu
committed
[#3315] use stopAndPoll
1 parent 47eb08f commit a070713

File tree

68 files changed

+204
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+204
-455
lines changed

Diff for: src/bin/agent/ca_process.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ CtrlAgentProcess::run() {
9090

9191
size_t
9292
CtrlAgentProcess::runIO() {
93+
// Handle events registered by hooks using external IOService objects.
9394
IOServiceMgr::instance().pollIOServices();
9495
size_t cnt = getIOService()->poll();
9596
if (!cnt) {
@@ -195,8 +196,9 @@ CtrlAgentProcess::configure(isc::data::ConstElementPtr config_set,
195196
int rcode = 0;
196197
config::parseAnswer(rcode, answer);
197198

198-
/// Let postponed hook initializations to run.
199+
/// Let postponed hook initializations run.
199200
try {
201+
// Handle events registered by hooks using external IOService objects.
200202
IOServiceMgr::instance().pollIOServices();
201203
} catch (const std::exception& ex) {
202204
std::ostringstream err;

Diff for: src/bin/agent/tests/ca_command_mgr_unittests.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ class CtrlAgentCommandMgrTest : public DControllerTest {
248248

249249
// We have some cancelled operations for which we need to invoke the
250250
// handlers with the operation_aborted error code.
251-
getIOService()->stop();
252-
getIOService()->restart();
253-
getIOService()->poll();
251+
getIOService()->stopAndPoll(false);
254252

255253
EXPECT_EQ(expected_responses, server_socket_->getResponseNum());
256254
checkAnswer(answer, expected_result0, expected_result1, expected_result2);
@@ -414,9 +412,7 @@ TEST_F(CtrlAgentCommandMgrTest, forwardListCommands) {
414412

415413
// We have some cancelled operations for which we need to invoke the
416414
// handlers with the operation_aborted error code.
417-
getIOService()->stop();
418-
getIOService()->restart();
419-
getIOService()->poll();
415+
getIOService()->stopAndPoll(false);
420416

421417
// Answer of 3 is specific to the stub response we send when the
422418
// command is forwarded. So having this value returned means that

Diff for: src/bin/agent/tests/ca_process_unittests.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ TEST_F(CtrlAgentProcessTest, shutdown) {
8686
elapsed.total_milliseconds() <= 400);
8787

8888
timer.cancel();
89-
getIOService()->stop();
90-
getIOService()->restart();
91-
try {
92-
getIOService()->poll();
93-
} catch (...) {
94-
}
89+
getIOService()->stopAndPoll();
9590
}
9691

9792
}

Diff for: src/bin/d2/d2_hooks.dox

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ to the end of this list.
5757
its (re)configuration. The server provides received and parsed configuration
5858
structures to the hook library.
5959
If the library uses any IO operations, it should create a local IOService
60-
object and register it to the IOServiceMgr. This way the local IOService is
60+
object and register it with the IOServiceMgr. This way the local IOService is
6161
used by the server to run asynchronous operations. The hooks library can use
6262
the local IOService object to schedule asynchronous tasks which are triggered
6363
by the D2 server's main loop. The hook library can use the local IOService

Diff for: src/bin/d2/d2_process.cc

+4-7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ D2Process::run() {
131131

132132
size_t
133133
D2Process::runIO() {
134+
// Handle events registered by hooks using external IOService objects.
134135
IOServiceMgr::instance().pollIOServices();
135136
// We want to block until at least one handler is called. We'll use
136137
// boost::asio::io_service directly for two reasons. First off
@@ -303,8 +304,9 @@ D2Process::configure(isc::data::ConstElementPtr config_set, bool check_only) {
303304
}
304305
}
305306

306-
/// Let postponed hook initializations to run.
307+
/// Let postponed hook initializations run.
307308
try {
309+
// Handle events registered by hooks using external IOService objects.
308310
IOServiceMgr::instance().pollIOServices();
309311
} catch (const std::exception& ex) {
310312
std::ostringstream err;
@@ -452,12 +454,7 @@ D2Process::reconfigureQueueMgr() {
452454

453455
D2Process::~D2Process() {
454456
queue_mgr_->stopListening();
455-
getIOService()->stop();
456-
getIOService()->restart();
457-
try {
458-
getIOService()->poll();
459-
} catch (...) {
460-
}
457+
getIOService()->stopAndPoll();
461458
queue_mgr_->removeListener();
462459
}
463460

Diff for: src/bin/d2/tests/d2_process_unittests.cc

+2-12
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,7 @@ TEST_F(D2ProcessTest, normalShutdown) {
585585
elapsed.total_milliseconds() <= 2200);
586586

587587
timer.cancel();
588-
getIOService()->stop();
589-
getIOService()->restart();
590-
try {
591-
getIOService()->poll();
592-
} catch (...) {
593-
}
588+
getIOService()->stopAndPoll();
594589
}
595590

596591
/// @brief Verifies that an "uncaught" exception thrown during event loop
@@ -617,12 +612,7 @@ TEST_F(D2ProcessTest, fatalErrorShutdown) {
617612
elapsed.total_milliseconds() <= 2200);
618613

619614
timer.cancel();
620-
getIOService()->stop();
621-
getIOService()->restart();
622-
try {
623-
getIOService()->poll();
624-
} catch (...) {
625-
}
615+
getIOService()->stopAndPoll();
626616
}
627617

628618
/// @brief Used to permit visual inspection of logs to ensure

Diff for: src/bin/d2/tests/d2_queue_mgr_unittests.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,7 @@ class QueueMgrUDPTest : public virtual ::testing::Test, public D2StatTest {
250250
sender_->stopSending();
251251
queue_mgr_->stopListening();
252252
test_timer_.cancel();
253-
io_service_->stop();
254-
io_service_->restart();
255-
try {
256-
io_service_->poll();
257-
} catch (...) {
258-
}
253+
io_service_->stopAndPoll();
259254
queue_mgr_->removeListener();
260255
}
261256

Diff for: src/bin/d2/tests/d2_update_mgr_unittests.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,7 @@ class D2UpdateMgrTest : public TimedIO, public ConfigParseTest {
8585
if (server_) {
8686
server_->stop();
8787
}
88-
io_service_->stop();
89-
io_service_->restart();
90-
try {
91-
io_service_->poll();
92-
} catch (...) {
93-
}
88+
io_service_->stopAndPoll();
9489
}
9590

9691
/// @brief Creates a list of valid NameChangeRequest.

Diff for: src/bin/dhcp4/ctrl_dhcp4_srv.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ ControlledDhcpv4Srv::commandConfigSetHandler(const string&,
453453
LOG_FATAL(dhcp4_logger, DHCP4_CONFIG_UNRECOVERABLE_ERROR);
454454
}
455455

456-
/// Let postponed hook initializations to run.
456+
/// Let postponed hook initializations run.
457457
try {
458+
// Handle events registered by hooks using external IOService objects.
458459
IOServiceMgr::instance().pollIOServices();
459460
} catch (const std::exception& ex) {
460461
std::ostringstream err;

Diff for: src/bin/dhcp4/dhcp4_hooks.dox

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ to the end of this list.
5757
its (re)configuration. The server provides received and parsed configuration
5858
structures to the hook library.
5959
If the library uses any IO operations, it should create a local IOService
60-
object and register it to the IOServiceMgr. This way the local IOService is
60+
object and register it with the IOServiceMgr. This way the local IOService is
6161
used by the server to run asynchronous operations. The hooks library can use
6262
the local IOService object to schedule asynchronous tasks which are triggered
6363
by the DHCP server's main loop. The hook library can use the local IOService

Diff for: src/bin/dhcp4/dhcp4_srv.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,7 @@ Dhcpv4Srv::~Dhcpv4Srv() {
708708
LOG_ERROR(dhcp4_logger, DHCP4_SRV_UNLOAD_LIBRARIES_ERROR).arg(msg);
709709
}
710710
IOServiceMgr::instance().clearIOServices();
711-
io_service_->stop();
712-
io_service_->restart();
713-
try {
714-
io_service_->poll();
715-
} catch (...) {
716-
}
711+
io_service_->stopAndPoll();
717712
}
718713

719714
void
@@ -1134,6 +1129,7 @@ Dhcpv4Srv::run() {
11341129
#endif // ENABLE_AFL
11351130
try {
11361131
runOne();
1132+
// Handle events registered by hooks using external IOService objects.
11371133
IOServiceMgr::instance().pollIOServices();
11381134
getIOService()->poll();
11391135
} catch (const std::exception& e) {

Diff for: src/bin/dhcp4/json_config_parser.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,9 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
937937
return (notify_libraries);
938938
}
939939

940-
/// Let postponed hook initializations to run.
940+
/// Let postponed hook initializations run.
941941
try {
942+
// Handle events registered by hooks using external IOService objects.
942943
IOServiceMgr::instance().pollIOServices();
943944
} catch (const std::exception& ex) {
944945
std::ostringstream err;

Diff for: src/bin/dhcp6/ctrl_dhcp6_srv.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,9 @@ ControlledDhcpv6Srv::commandConfigSetHandler(const string&,
455455
LOG_FATAL(dhcp6_logger, DHCP6_CONFIG_UNRECOVERABLE_ERROR);
456456
}
457457

458-
/// Let postponed hook initializations to run.
458+
/// Let postponed hook initializations run.
459459
try {
460+
// Handle events registered by hooks using external IOService objects.
460461
IOServiceMgr::instance().pollIOServices();
461462
} catch (const std::exception& ex) {
462463
std::ostringstream err;

Diff for: src/bin/dhcp6/dhcp6_hooks.dox

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ to the end of this list.
5757
its (re)configuration. The server provides received and parsed configuration
5858
structures to the hook library.
5959
If the library uses any IO operations, it should create a local IOService
60-
object and register it to the IOServiceMgr. This way the local IOService is
60+
object and register it with the IOServiceMgr. This way the local IOService is
6161
used by the server to run asynchronous operations. The hooks library can use
6262
the local IOService object to schedule asynchronous tasks which are triggered
6363
by the DHCP server's main loop. The hook library can use the local IOService

Diff for: src/bin/dhcp6/dhcp6_srv.cc

+2-6
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,7 @@ Dhcpv6Srv::~Dhcpv6Srv() {
304304
LOG_ERROR(dhcp6_logger, DHCP6_SRV_UNLOAD_LIBRARIES_ERROR).arg(msg);
305305
}
306306
IOServiceMgr::instance().clearIOServices();
307-
io_service_->stop();
308-
io_service_->restart();
309-
try {
310-
io_service_->poll();
311-
} catch (...) {
312-
}
307+
io_service_->stopAndPoll();
313308
}
314309

315310
void Dhcpv6Srv::shutdown() {
@@ -615,6 +610,7 @@ Dhcpv6Srv::run() {
615610
#endif // ENABLE_AFL
616611
try {
617612
runOne();
613+
// Handle events registered by hooks using external IOService objects.
618614
IOServiceMgr::instance().pollIOServices();
619615
getIOService()->poll();
620616
} catch (const std::exception& e) {

Diff for: src/bin/dhcp6/json_config_parser.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,9 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
10701070
return (notify_libraries);
10711071
}
10721072

1073-
/// Let postponed hook initializations to run.
1073+
/// Let postponed hook initializations run.
10741074
try {
1075+
// Handle events registered by hooks using external IOService objects.
10751076
IOServiceMgr::instance().pollIOServices();
10761077
} catch (const std::exception& ex) {
10771078
std::ostringstream err;

Diff for: src/bin/dhcp6/tests/dhcp6_process_tests.sh.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export KEA_LFC_EXECUTABLE="@abs_top_builddir@/src/bin/lfc/kea-lfc"
2121
# Path to test hooks library
2222
HOOK_FAIL_LOAD_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco3.so"
2323
# Path to test hooks library
24-
HOOK_FAIL_POLL_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco3.so"
24+
HOOK_FAIL_POLL_PATH="@abs_top_builddir@/src/bin/dhcp6/tests/.libs/libco4.so"
2525
# Kea configuration to be stored in the configuration file.
2626
CONFIG="{
2727
\"Dhcp6\":

Diff for: src/bin/dhcp6/tests/dhcp6_test_utils.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,7 @@ class NakedDhcpv6Srv: public isc::dhcp::Dhcpv6Srv {
218218
virtual ~NakedDhcpv6Srv() {
219219
// Close the lease database
220220
isc::dhcp::LeaseMgrFactory::destroy();
221-
getIOService()->stop();
222-
getIOService()->restart();
223-
try {
224-
getIOService()->poll();
225-
} catch (...) {
226-
}
221+
getIOService()->stopAndPoll();
227222
}
228223

229224
/// @brief Processes incoming Solicit message.

Diff for: src/bin/netconf/http_control_socket.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,7 @@ HttpControlSocket::sendCommand(ConstElementPtr command) {
102102
io_service->run();
103103

104104
client.stop();
105-
io_service->stop();
106-
io_service->restart();
107-
try {
108-
io_service->poll();
109-
} catch (...) {
110-
}
105+
io_service->stopAndPoll();
111106

112107
if (received_ec) {
113108
// Got an error code.

Diff for: src/bin/netconf/netconf_process.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ NetconfProcess::run() {
6666

6767
size_t
6868
NetconfProcess::runIO() {
69+
// Handle events registered by hooks using external IOService objects.
6970
IOServiceMgr::instance().pollIOServices();
7071
size_t cnt = getIOService()->poll();
7172
if (!cnt) {
@@ -88,8 +89,9 @@ NetconfProcess::configure(isc::data::ConstElementPtr config_set,
8889
int rcode = 0;
8990
config::parseAnswer(rcode, answer);
9091

91-
/// Let postponed hook initializations to run.
92+
/// Let postponed hook initializations run.
9293
try {
94+
// Handle events registered by hooks using external IOService objects.
9395
IOServiceMgr::instance().pollIOServices();
9496
} catch (const std::exception& ex) {
9597
std::ostringstream err;

Diff for: src/bin/netconf/tests/control_socket_unittests.cc

+2-12
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,7 @@ class UnixControlSocketTest : public ThreadedTest {
158158
thread_.reset();
159159
}
160160
removeUnixSocketFile();
161-
io_service_->stop();
162-
io_service_->restart();
163-
try {
164-
io_service_->poll();
165-
} catch (...) {
166-
}
161+
io_service_->stopAndPoll();
167162
}
168163

169164
/// @brief Returns socket file path.
@@ -530,12 +525,7 @@ class HttpControlSocketTest : public ThreadedTest {
530525
if (listener_) {
531526
listener_->stop();
532527
}
533-
io_service_->stop();
534-
io_service_->restart();
535-
try {
536-
io_service_->poll();
537-
} catch (...) {
538-
}
528+
io_service_->stopAndPoll();
539529
listener_.reset();
540530
}
541531

Diff for: src/bin/netconf/tests/netconf_process_unittests.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ TEST_F(NetconfProcessTest, shutdown) {
8181
EXPECT_TRUE(elapsed.total_milliseconds() >= 100 &&
8282
elapsed.total_milliseconds() <= 400);
8383
timer.cancel();
84-
getIOService()->stop();
85-
getIOService()->restart();
86-
try {
87-
getIOService()->poll();
88-
} catch (...) {
89-
}
84+
getIOService()->stopAndPoll();
9085
}
9186

9287
}

Diff for: src/bin/netconf/tests/netconf_unittests.cc

+1-6
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,7 @@ class NetconfAgentTest : public ThreadedTest {
130130
responses_.clear();
131131
removeUnixSocketFile();
132132
SysrepoSetup::cleanSharedMemory();
133-
io_service_->stop();
134-
io_service_->restart();
135-
try {
136-
io_service_->poll();
137-
} catch (...) {
138-
}
133+
io_service_->stopAndPoll();
139134
}
140135

141136
/// @brief Returns socket file path.

Diff for: src/hooks/dhcp/high_availability/ha.dox

+3-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ IOServiceMgr::instance().pollIOServices();
137137
which executes callbacks for completed asynchronous operations, such as
138138
timers, asynchronous sends and receives. The instance of the IOService
139139
is owned by the DHCP servers, but hooks libraries must create their own
140-
IOService access to schedule asynchronous tasks.
141-
The hook's IOService object must be registered on the IOServiceMgr by
140+
IOService to schedule asynchronous tasks.
141+
The hook's IOService object must be registered with the IOServiceMgr by
142142
calling registerIOService and must unregister it on "unload" hook point
143143
by calling unregisterIOService.
144144

@@ -163,6 +163,7 @@ Dhcpv[4|6]Srv::run() {
163163
[...]
164164
try {
165165
runOne();
166+
// Handle events registered by hooks using external IOService objects.
166167
IOServiceMgr::instance().pollIOServices();
167168
getIOService()->poll();
168169
} catch (const std::exception& e) {

0 commit comments

Comments
 (0)