]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3190] use smart pointer to capture IOService instance
authorRazvan Becheriu <razvan@isc.org>
Thu, 14 Dec 2023 18:16:52 +0000 (20:16 +0200)
committerRazvan Becheriu <razvan@isc.org>
Tue, 5 Mar 2024 07:50:05 +0000 (07:50 +0000)
108 files changed:
src/bin/agent/ca_command_mgr.cc
src/bin/agent/ca_process.cc
src/bin/agent/tests/ca_command_mgr_unittests.cc
src/bin/agent/tests/ca_controller_unittests.cc
src/bin/agent/tests/ca_process_unittests.cc
src/bin/d2/d2_queue_mgr.cc
src/bin/d2/tests/d2_controller_unittests.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/tests/kea_controller_unittest.cc
src/bin/dhcp6/tests/kea_controller_unittest.cc
src/bin/netconf/http_control_socket.cc
src/bin/netconf/tests/control_socket_unittests.cc
src/bin/netconf/tests/netconf_controller_unittests.cc
src/bin/netconf/tests/netconf_process_unittests.cc
src/bin/netconf/tests/netconf_unittests.cc
src/bin/netconf/unix_control_socket.cc
src/hooks/dhcp/high_availability/communication_state.cc
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
src/hooks/dhcp/high_availability/tests/ha_test.cc
src/lib/asiodns/io_fetch.cc
src/lib/asiodns/io_fetch.h
src/lib/asiodns/tests/io_fetch_unittest.cc
src/lib/asiolink/botan_boost_tls.h
src/lib/asiolink/botan_tls.h
src/lib/asiolink/common_tls.h
src/lib/asiolink/interval_timer.cc
src/lib/asiolink/interval_timer.h
src/lib/asiolink/io_acceptor.h
src/lib/asiolink/io_service_signal.cc
src/lib/asiolink/io_service_signal.h
src/lib/asiolink/openssl_tls.h
src/lib/asiolink/tcp_acceptor.h
src/lib/asiolink/tcp_socket.h
src/lib/asiolink/tests/interval_timer_unittest.cc
src/lib/asiolink/tests/io_service_signal_unittests.cc
src/lib/asiolink/tests/process_spawn_unittest.cc
src/lib/asiolink/tests/tcp_acceptor_unittest.cc
src/lib/asiolink/tests/tcp_socket_unittest.cc
src/lib/asiolink/tests/tls_acceptor_unittest.cc
src/lib/asiolink/tests/tls_socket_unittest.cc
src/lib/asiolink/tests/tls_unittest.cc
src/lib/asiolink/tests/udp_socket_unittest.cc
src/lib/asiolink/tests/unix_domain_socket_unittest.cc
src/lib/asiolink/testutils/test_server_unix_socket.cc
src/lib/asiolink/testutils/test_server_unix_socket.h
src/lib/asiolink/testutils/timed_signal.h
src/lib/asiolink/tls_acceptor.h
src/lib/asiolink/tls_socket.h
src/lib/asiolink/udp_socket.h
src/lib/asiolink/unix_domain_socket.cc
src/lib/asiolink/unix_domain_socket.h
src/lib/asiolink/unix_domain_socket_acceptor.h
src/lib/config/client_connection.cc
src/lib/config/client_connection.h
src/lib/config/cmd_http_listener.cc
src/lib/config/command_mgr.cc
src/lib/config/tests/client_connection_unittests.cc
src/lib/config/tests/cmd_http_listener_unittests.cc
src/lib/d2srv/dns_client.cc
src/lib/d2srv/dns_client.h
src/lib/d2srv/nc_trans.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/d2srv/testutils/nc_test_utils.h
src/lib/dhcp_ddns/ncr_io.cc
src/lib/dhcp_ddns/ncr_io.h
src/lib/dhcp_ddns/ncr_udp.cc
src/lib/dhcp_ddns/ncr_udp.h
src/lib/dhcp_ddns/tests/ncr_udp_unittests.cc
src/lib/dhcpsrv/d2_client_mgr.cc
src/lib/dhcpsrv/d2_client_mgr.h
src/lib/dhcpsrv/tests/cfg_expiration_unittest.cc
src/lib/dhcpsrv/tests/cfg_iface_unittest.cc
src/lib/dhcpsrv/tests/d2_udp_unittest.cc
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/timer_mgr_unittest.cc
src/lib/dhcpsrv/timer_mgr.cc
src/lib/http/client.cc
src/lib/http/client.h
src/lib/http/connection.cc
src/lib/http/connection.h
src/lib/http/listener.cc
src/lib/http/listener.h
src/lib/http/listener_impl.cc
src/lib/http/listener_impl.h
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/test_http_client.h
src/lib/http/tests/tls_client_unittests.cc
src/lib/http/tests/tls_server_unittests.cc
src/lib/process/tests/d_controller_unittests.cc
src/lib/process/testutils/d_test_stubs.cc
src/lib/tcp/mt_tcp_listener_mgr.cc
src/lib/tcp/mt_tcp_listener_mgr.h
src/lib/tcp/tcp_connection.cc
src/lib/tcp/tcp_connection.h
src/lib/tcp/tcp_listener.cc
src/lib/tcp/tcp_listener.h
src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc
src/lib/tcp/tests/tcp_listener_unittests.cc
src/lib/tcp/tests/tcp_test_client.h
src/lib/tcp/tests/tcp_test_listener.h
src/lib/tcp/tests/tls_listener_unittests.cc

index 848753d333afd1e101a56ea5f98f674f2ee8f0ef..2fa35b0b50e4525e0436a382a9d3646fa61d6daa 100644 (file)
@@ -226,7 +226,7 @@ CtrlAgentCommandMgr::forwardCommand(const std::string& service,
 
     // Forward command and receive reply.
     IOServicePtr io_service(new IOService());;
-    ClientConnection conn(*io_service);
+    ClientConnection conn(io_service);
     boost::system::error_code received_ec;
     ConstJSONFeedPtr received_feed;
     conn.start(ClientConnection::SocketPath(socket_name),
index 0c6128f66a602dbc4a8ccb4ff8d00d2718cab410..fd36a46e4221d486b051102ae9a0018a005cabbd 100644 (file)
@@ -164,7 +164,7 @@ CtrlAgentProcess::configure(isc::data::ConstElementPtr config_set,
             // Create http listener. It will open up a TCP socket and be
             // prepared to accept incoming connection.
             HttpListenerPtr http_listener
-                (new HttpListener(*getIOService(), server_address,
+                (new HttpListener(getIOService(), server_address,
                                   server_port, tls_context, rcf,
                                   HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND),
                                   HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT)));
index 9eceedfc77bb64ea123711c8c967f5e3a5451d72..05ec8c7bc77a5f58ee862a8165872981f7b52af6 100644 (file)
@@ -170,7 +170,7 @@ public:
     /// @param use_thread Indicates if the IO service will be ran in thread.
     void bindServerSocket(const std::string& response,
                           const bool use_thread = false) {
-        server_socket_.reset(new test::TestServerUnixSocket(*getIOService(),
+        server_socket_.reset(new test::TestServerUnixSocket(getIOService(),
                                                             unixSocketFilePath(),
                                                             response));
         server_socket_->startTimer(TEST_TIMEOUT);
index 3ffab4452e3ee4b7caa168b729e19293c2d87cdf..1e0c58c30ee36b909527c9314d97b0e5db895322 100644 (file)
@@ -242,7 +242,7 @@ TEST_F(CtrlAgentControllerTest, launchNormalShutdown) {
 // Tests that the SIGINT triggers a normal shutdown.
 TEST_F(CtrlAgentControllerTest, sigintShutdown) {
     // Setup to raise SIGHUP in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGINT, 1);
+    TimedSignal sighup(getIOService(), SIGINT, 1);
 
     // Write valid_agent_config and then run launch() for a maximum
     // of 1000 ms.
@@ -258,7 +258,7 @@ TEST_F(CtrlAgentControllerTest, sigintShutdown) {
 // Tests that the SIGTERM triggers a normal shutdown.
 TEST_F(CtrlAgentControllerTest, sigtermShutdown) {
     // Setup to raise SIGTERM in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGTERM, 1);
+    TimedSignal sighup(getIOService(), SIGTERM, 1);
 
     // Write valid_agent_config and then run launch() for a maximum of 1 s.
     time_duration elapsed_time;
@@ -307,7 +307,7 @@ TEST_F(CtrlAgentControllerTest, successfulConfigUpdate) {
     // Schedule reconfiguration.
     scheduleTimedWrite(second_config, 100);
     // Schedule SIGHUP signal to trigger reconfiguration.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Start the server.
     time_duration elapsed_time;
@@ -372,7 +372,7 @@ TEST_F(CtrlAgentControllerTest, unsuccessfulConfigUpdate) {
     // Schedule reconfiguration.
     scheduleTimedWrite(second_config, 100);
     // Schedule SIGHUP signal to trigger reconfiguration.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Start the server.
     time_duration elapsed_time;
@@ -438,7 +438,7 @@ TEST_F(CtrlAgentControllerTest, noListenerChange) {
     // Schedule reconfiguration.
     scheduleTimedWrite(second_config, 100);
     // Schedule SIGHUP signal to trigger reconfiguration.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Start the server.
     time_duration elapsed_time;
index 6f9bd12d97ac0ff5c7eb9bdd466af9a962181ec4..ecb256318850f976863573d5e3ce7c67e9513ee3 100644 (file)
@@ -67,7 +67,7 @@ TEST(CtrlAgentProcess, construction) {
 TEST_F(CtrlAgentProcessTest, shutdown) {
     // Use an asiolink IntervalTimer and callback to generate the
     // shutdown invocation. (Note IntervalTimer setup is in milliseconds).
-    IntervalTimer timer(*getIOService());
+    IntervalTimer timer(getIOService());
     timer.setup(std::bind(&CtrlAgentProcessTest::genShutdownCallback, this),
                 200);
 
index 71949b3bcfa4d5da06f52a2114169bfcf323309c..12efe742e8fcb5b915fb3cf7967cf08d7416f455 100644 (file)
@@ -131,7 +131,7 @@ D2QueueMgr::startListening() {
 
     // Instruct the listener to start listening and set state accordingly.
     try {
-        listener_->startListening(*io_service_);
+        listener_->startListening(io_service_);
         mgr_state_ = RUNNING;
     } catch (const isc::Exception& ex) {
         isc_throw(D2QueueMgrError, "D2QueueMgr listener start failed: "
index 6725d87480e1b014e119c3feb49b6c5bba36d630..76ed9e826b68c5593eb7fb8839e11a068e99d594 100644 (file)
@@ -207,7 +207,7 @@ TEST_F(D2ControllerTest, invalidConfigReload) {
     scheduleTimedWrite("{ \"string_test\": BOGUS JSON }", 100);
 
     // Setup to raise SIGHUP in 200 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Write valid_d2_config and then run launch() for a maximum of 500 ms.
     time_duration elapsed_time;
@@ -246,7 +246,7 @@ TEST_F(D2ControllerTest, validConfigReload) {
     scheduleTimedWrite(second_cfg, 100);
 
     // Setup to raise SIGHUP in 200 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Write valid_d2_config and then run launch() for a maximum of 500ms.
     time_duration elapsed_time;
@@ -269,7 +269,7 @@ TEST_F(D2ControllerTest, validConfigReload) {
 // Tests that the SIGINT triggers a normal shutdown.
 TEST_F(D2ControllerTest, sigintShutdown) {
     // Setup to raise SIGINT in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGINT, 1);
+    TimedSignal sighup(getIOService(), SIGINT, 1);
 
     // Write valid_d2_config and then run launch() for a maximum of 1000 ms.
     time_duration elapsed_time;
@@ -286,7 +286,7 @@ TEST_F(D2ControllerTest, sigintShutdown) {
 // Tests that the SIGTERM triggers a normal shutdown.
 TEST_F(D2ControllerTest, sigtermShutdown) {
     // Setup to raise SIGTERM in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGTERM, 1);
+    TimedSignal sighup(getIOService(), SIGTERM, 1);
 
     // Write valid_d2_config and then run launch() for a maximum of 1 s.
     time_duration elapsed_time;
index e2e11b2a742ba0886312743c4fe2e06a8c8925cb..bc6be18a172912c6685431d0878e468262a54e23 100644 (file)
@@ -561,7 +561,7 @@ TEST_F(D2ProcessTest, canShutdown) {
 TEST_F(D2ProcessTest, normalShutdown) {
     // Use an asiolink IntervalTimer and callback to generate the
     // shutdown invocation. (Note IntervalTimer setup is in milliseconds).
-    isc::asiolink::IntervalTimer timer(*getIOService());
+    isc::asiolink::IntervalTimer timer(getIOService());
     timer.setup(std::bind(&D2ProcessTest::genShutdownCallback, this),
                 2 * 1000);
 
@@ -585,7 +585,7 @@ TEST_F(D2ProcessTest, normalShutdown) {
 TEST_F(D2ProcessTest, fatalErrorShutdown) {
     // Use an asiolink IntervalTimer and callback to generate the
     // the exception.  (Note IntervalTimer setup is in milliseconds).
-    isc::asiolink::IntervalTimer timer(*getIOService());
+    isc::asiolink::IntervalTimer timer(getIOService());
     timer.setup(std::bind(&D2ProcessTest::genFatalErrorCallback, this),
                 2 * 1000);
 
index e5e3f117aef6f84590cdd70741e91bc691ffbcd9..dbbeec807b3fe2fd24e1dbcddfc65251e9d13dc2 100644 (file)
@@ -209,7 +209,7 @@ class QueueMgrUDPTest : public virtual ::testing::Test, public D2StatTest,
                         NameChangeSender::RequestSendHandler {
 public:
     asiolink::IOServicePtr io_service_;
-    NameChangeSenderPtr   sender_;
+    NameChangeSenderPtr sender_;
     isc::asiolink::IntervalTimer test_timer_;
     D2QueueMgrPtr queue_mgr_;
 
@@ -218,7 +218,7 @@ public:
     std::vector<NameChangeRequestPtr> received_ncrs_;
 
     QueueMgrUDPTest() : io_service_(new isc::asiolink::IOService()),
-                        test_timer_(*io_service_),
+                        test_timer_(io_service_),
                         send_result_(NameChangeSender::SUCCESS) {
         isc::asiolink::IOAddress addr(TEST_ADDRESS);
         // Create our sender instance. Note that reuse_address is true.
@@ -359,7 +359,7 @@ TEST_F (QueueMgrUDPTest, liveFeed) {
     ASSERT_EQ(D2QueueMgr::RUNNING, queue_mgr_->getMgrState());
 
     // Place the sender into sending state.
-    ASSERT_NO_THROW(sender_->startSending(*io_service_));
+    ASSERT_NO_THROW(sender_->startSending(io_service_));
     ASSERT_TRUE(sender_->amSending());
 
     // Iterate over the list of requests sending and receiving
index 028b5986d88d4030a9ba8d4d1f2c9db621b4506a..920ccc884e68b2b1c93eb9ec4d5b77f2470680b1 100644 (file)
@@ -692,7 +692,7 @@ TEST_F(D2UpdateMgrTest, addTransaction) {
 
     // Create a server based on the transaction's current server, and
     // start it listening.
-    FauxServer server(*io_service_, *(trans->getCurrentServer()));
+    FauxServer server(io_service_, *(trans->getCurrentServer()));
     server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Run sweep and IO until everything is done.
@@ -747,9 +747,9 @@ TEST_F(D2UpdateMgrTest, removeTransaction) {
     ASSERT_EQ(1, trans->getUpdateAttempts());
     ASSERT_EQ(StateModel::NOP_EVT, trans->getNextEvent());
 
-    // Create a server based on the transaction's current server,
-    // and start it listening.
-    FauxServer server(*io_service_, *(trans->getCurrentServer()));
+    // Create a server based on the transaction's current server, and
+    // start it listening.
+    FauxServer server(io_service_, *(trans->getCurrentServer()));
     server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Run sweep and IO until everything is done.
@@ -797,7 +797,7 @@ TEST_F(D2UpdateMgrTest, errorTransaction) {
     ASSERT_TRUE(trans->getCurrentServer());
 
     // Create a server and start it listening.
-    FauxServer server(*io_service_, *(trans->getCurrentServer()));
+    FauxServer server(io_service_, *(trans->getCurrentServer()));
     server.receive(FauxServer::CORRUPT_RESP);
 
     // Run sweep and IO until everything is done.
@@ -836,7 +836,7 @@ TEST_F(D2UpdateMgrTest, multiTransaction) {
     // that all of configured servers have the same address.
     // and start it listening.
     asiolink::IOAddress server_ip("127.0.0.1");
-    FauxServer server(*io_service_, server_ip, 5301);
+    FauxServer server(io_service_, server_ip, 5301);
     server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Run sweep and IO until everything is done.
@@ -908,7 +908,7 @@ TEST_F(D2UpdateMgrTest, simpleAddTransaction) {
 
     // Create a server based on the transaction's current server, and
     // start it listening.
-    FauxServer server(*io_service_, *(trans->getCurrentServer()));
+    FauxServer server(io_service_, *(trans->getCurrentServer()));
     server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Run sweep and IO until everything is done.
@@ -964,9 +964,9 @@ TEST_F(D2UpdateMgrTest, simpleRemoveTransaction) {
     ASSERT_EQ(1, trans->getUpdateAttempts());
     ASSERT_EQ(StateModel::NOP_EVT, trans->getNextEvent());
 
-    // Create a server based on the transaction's current server,
-    // and start it listening.
-    FauxServer server(*io_service_, *(trans->getCurrentServer()));
+    // Create a server based on the transaction's current server, and
+    // start it listening.
+    FauxServer server(io_service_, *(trans->getCurrentServer()));
     server.receive(FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Run sweep and IO until everything is done.
index 9e06434fec438cd6226231865afd15d40d898536..f5877d8f363e4ef5ac5cd6414b638f0d0dcbbc42 100644 (file)
@@ -229,7 +229,7 @@ public:
     /// stops the IO service and causes the function to return.
     void runTimersWithTimeout(const IOServicePtr& io_service, const long timeout_ms,
                               std::function<bool()> cond = std::function<bool()>()) {
-        IntervalTimer timer(*io_service);
+        IntervalTimer timer(io_service);
         std::atomic<bool> stopped(false);
         timer.setup([&io_service, &stopped]() {
             stopped = true;
index 2458cb9d6bfe0a0593d3384ac79308da804d49af..068fc96845a77b47b0442402ba286921fd63da44 100644 (file)
@@ -216,7 +216,7 @@ public:
     /// stops the IO service and causes the function to return.
     void runTimersWithTimeout(const IOServicePtr& io_service, const long timeout_ms,
                               std::function<bool()> cond = std::function<bool()>()) {
-        IntervalTimer timer(*io_service);
+        IntervalTimer timer(io_service);
         std::atomic<bool> stopped(false);
         timer.setup([&io_service, &stopped]() {
             stopped = true;
index 02f5b50738bca5c82ff1b395b3c95fde68b16c1c..197c51916c2dfa130aafb03577624b9a7b2e6022 100644 (file)
@@ -79,7 +79,7 @@ HttpControlSocket::sendCommand(ConstElementPtr command) {
     }
 
     IOServicePtr io_service(new IOService());
-    HttpClient client(*io_service, false);
+    HttpClient client(io_service, false);
     boost::system::error_code received_ec;
     string receive_errmsg;
     HttpResponseJsonPtr response(new HttpResponseJson());
index c284a226d1a149d8609404cee800c5dcbe0dab46..996bcbae40447a84b186df440180dd4509752305 100644 (file)
@@ -144,7 +144,7 @@ public:
 
     /// @brief Constructor.
     UnixControlSocketTest()
-        : ThreadedTest(), io_service_() {
+        : ThreadedTest(), io_service_(new IOService()) {
     }
 
     void SetUp() override {
@@ -160,7 +160,7 @@ public:
         // io_service must be stopped after the thread returns,
         // otherwise the thread may never return if it is
         // waiting for the completion of some asynchronous tasks.
-        io_service_.stop();
+        io_service_->stop();
         removeUnixSocketFile();
     }
 
@@ -200,7 +200,7 @@ public:
     void reflectServer();
 
     /// @brief IOService object.
-    IOService io_service_;
+    IOServicePtr io_service_;
 };  // UnixControlSocketTest
 
 /// @brief Server method running in a thread reflecting the command.
@@ -211,14 +211,14 @@ void
 UnixControlSocketTest::reflectServer() {
     // Acceptor.
     boost::asio::local::stream_protocol::acceptor
-        acceptor(io_service_.getInternalIOService());
+        acceptor(io_service_->getInternalIOService());
     EXPECT_NO_THROW_LOG(acceptor.open());
     boost::asio::local::stream_protocol::endpoint
         endpoint(unixSocketFilePath());
     EXPECT_NO_THROW_LOG(acceptor.bind(endpoint));
     EXPECT_NO_THROW_LOG(acceptor.listen());
     boost::asio::local::stream_protocol::socket
-        socket(io_service_.getInternalIOService());
+        socket(io_service_->getInternalIOService());
 
     // Ready.
     signalReady();
@@ -241,7 +241,7 @@ UnixControlSocketTest::reflectServer() {
                               accepted = true;
                           });
     while (!accepted && !timeout) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
     ASSERT_FALSE(ec);
 
@@ -255,7 +255,7 @@ UnixControlSocketTest::reflectServer() {
                              received = cnt;
                          });
     while (!received && !timeout) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
     ASSERT_FALSE(ec);
     rbuf.resize(received);
@@ -274,7 +274,7 @@ UnixControlSocketTest::reflectServer() {
                           sent = cnt;
                       });
     while (!sent && !timeout) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
     ASSERT_FALSE(ec);
 
@@ -511,6 +511,10 @@ public:
 /// @brief Test fixture class for http control sockets.
 class HttpControlSocketTest : public ThreadedTest {
 public:
+    /// @brief Constructor.
+    HttpControlSocketTest() : io_service_(new IOService()) {
+    }
+
     void SetUp() override {
         SysrepoSetup::cleanSharedMemory();
     }
@@ -524,7 +528,7 @@ public:
         // io_service must be stopped after the thread returns,
         // otherwise the thread may never return if it is
         // waiting for the completion of some asynchronous tasks.
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Returns socket URL.
@@ -562,12 +566,12 @@ public:
             signalReady();
             // Until stop() is called run IO service.
             while (!isStopping()) {
-                io_service_.runOne();
+                io_service_->runOne();
             }
             // Main thread signalled that the thread should
             // terminate. Launch any outstanding IO service
             // handlers.
-            io_service_.poll();
+            io_service_->poll();
             // Nothing more to do. Signal that the thread is
             // done so as the main thread can close HTTP
             // listener and clean up after the test.
@@ -587,7 +591,7 @@ public:
         // If the thread is blocked on running the IO
         // service, post the empty handler to cause
         // runOne to return.
-        io_service_.post([]() { return; });
+        io_service_->post([]() { return; });
         // We asked that the thread stops. Let's wait
         // for it to signal that it has stopped.
         waitStopped();
@@ -600,7 +604,7 @@ public:
     }
 
     /// @brief IOService object.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Pointer to listener.
     HttpListenerPtr listener_;
@@ -611,12 +615,11 @@ void
 HttpControlSocketTest::createReflectListener() {
     HttpResponseCreatorFactoryPtr
         factory(new TestHttpResponseCreatorFactory());
-    listener_.reset(new
-                HttpListener(io_service_,
-                             IOAddress(SERVER_ADDRESS), SERVER_PORT,
-                             TlsContextPtr(), factory,
-                             HttpListener::RequestTimeout(2000),
-                             HttpListener::IdleTimeout(2000)));
+    listener_.reset(new HttpListener(io_service_,
+                                     IOAddress(SERVER_ADDRESS), SERVER_PORT,
+                                     TlsContextPtr(), factory,
+                                     HttpListener::RequestTimeout(2000),
+                                     HttpListener::IdleTimeout(2000)));
 }
 
 // Verifies that the createControlSocket template can create a http
index 84fcfc024cd79d4ee8762bdb7105cde424e91dd8..774ee30506445f981a2478957403a79047614be6 100644 (file)
@@ -157,7 +157,7 @@ TEST_F(NetconfControllerTest, launchNormalShutdown) {
 // Tests that the SIGINT triggers a normal shutdown.
 TEST_F(NetconfControllerTest, sigintShutdown) {
     // Setup to raise SIGINT in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGINT, 1);
+    TimedSignal sighup(getIOService(), SIGINT, 1);
 
     // Write valid_netconf_config and then run launch() for a maximum
     // of 500 ms.
@@ -173,7 +173,7 @@ TEST_F(NetconfControllerTest, sigintShutdown) {
 // Tests that the SIGTERM triggers a normal shutdown.
 TEST_F(NetconfControllerTest, sigtermShutdown) {
     // Setup to raise SIGTERM in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGTERM, 1);
+    TimedSignal sighup(getIOService(), SIGTERM, 1);
 
     // Write valid_netconf_config and then run launch() for a maximum
     // of 500 ms.
index 0b82b6bbee61467aa02203a6f12a4a3247dcfaaa..3cfdbd040a1892025236367ad58fee3e6191c179 100644 (file)
@@ -63,7 +63,7 @@ TEST(NetconfProcess, construction) {
 TEST_F(NetconfProcessTest, shutdown) {
     // Use an asiolink IntervalTimer and callback to generate the
     // shutdown invocation. (Note IntervalTimer setup is in milliseconds).
-    IntervalTimer timer(*getIOService());
+    IntervalTimer timer(getIOService());
     timer.setup(std::bind(&NetconfProcessTest::genShutdownCallback, this),
                 200);
 
index 9a58b8a587d856d0c39197b511e861aace12ec79..fd3340d33ca5e5da9f198b37cee32c9289046eed 100644 (file)
@@ -275,7 +275,7 @@ NetconfAgentTest::fakeServer() {
 
     // Timeout.
     bool timeout = false;
-    IntervalTimer timer(*io_service_);
+    IntervalTimer timer(io_service_);
     timer.setup([&timeout]() {
             timeout = true;
             FAIL() << "timeout";
index e89e522612969ea4a17a0d5745aa952c8816dd6f..5eed6155151d712dfd6e41a00a066a29ede9deb4 100644 (file)
@@ -55,7 +55,7 @@ ConstElementPtr
 UnixControlSocket::sendCommand(ConstElementPtr command) {
     // We are using our own IO service because this method is synchronous.
     IOServicePtr io_service(new IOService());
-    ClientConnection conn(*io_service);
+    ClientConnection conn(io_service);
     boost::system::error_code received_ec;
     ConstJSONFeedPtr received_feed;
 
index d7f9cde03eee0d64d19e5db178e2cb742bc54c21..38b7566df3a2faacbd881aa14bf38db8dc4c7fa4 100644 (file)
@@ -207,7 +207,7 @@ CommunicationState::startHeartbeatInternal(const long interval,
     }
 
     if (!timer_) {
-        timer_.reset(new IntervalTimer(*io_service_));
+        timer_.reset(new IntervalTimer(io_service_));
     }
 
     if (settings_modified) {
index 471fad1806d635a812fcd8e66cdc74d92b91d3ec..d148afa81ee2ffeff2ba432a85f2cde0fb5a8d61 100644 (file)
@@ -94,10 +94,10 @@ HAService::HAService(const unsigned int id, const IOServicePtr& io_service,
     // Create the client and(or) listener as appropriate.
     if (!config_->getEnableMultiThreading()) {
         // Not configured for multi-threading, start a client in ST mode.
-        client_.reset(new HttpClient(*io_service_, false));
+        client_.reset(new HttpClient(io_service_, false));
     } else {
         // Create an MT-mode client.
-        client_.reset(new HttpClient(*io_service_, true,
+        client_.reset(new HttpClient(io_service_, true,
                       config_->getHttpClientThreads(), true));
 
         // If we're configured to use our own listener create and start it.
@@ -2347,10 +2347,9 @@ HAService::processSynchronize(const std::string& server_name,
 int
 HAService::synchronize(std::string& status_message, const std::string& server_name,
                        const unsigned int max_period) {
-
     lease_sync_filter_.apply();
 
-    IOService io_service;
+    IOServicePtr io_service(new IOService());
     HttpClient client(io_service, false);
 
     asyncSyncLeases(client, server_name, max_period, Lease4Ptr(),
@@ -2393,7 +2392,7 @@ HAService::synchronize(std::string& status_message, const std::string& server_na
                             // The synchronization process is completed, so let's break
                             // the IO service so as we can return the response to the
                             // controlling client.
-                            io_service.stop();
+                            io_service->stop();
                         });
 
                     } else {
@@ -2403,7 +2402,7 @@ HAService::synchronize(std::string& status_message, const std::string& server_na
                             status_message = error_message;
                         }
 
-                        io_service.stop();
+                        io_service->stop();
                     }
                 });
 
@@ -2423,7 +2422,7 @@ HAService::synchronize(std::string& status_message, const std::string& server_na
                     // The synchronization process is completed, so let's break
                     // the IO service so as we can return the response to the
                     // controlling client.
-                    io_service.stop();
+                    io_service->stop();
 
                 });
             }
@@ -2431,7 +2430,7 @@ HAService::synchronize(std::string& status_message, const std::string& server_na
         } else {
             // Also stop IO service if there is no need to enable DHCP
             // service.
-            io_service.stop();
+            io_service->stop();
         }
     });
 
@@ -2444,7 +2443,7 @@ HAService::synchronize(std::string& status_message, const std::string& server_na
 
     // Run the IO service until it is stopped by any of the callbacks. This
     // makes it synchronous.
-    io_service.run();
+    io_service->run();
 
     // End measuring duration.
     stopwatch.stop();
@@ -2562,7 +2561,7 @@ HAService::sendLeaseUpdatesFromBacklog() {
         return (true);
     }
 
-    IOService io_service;
+    IOServicePtr io_service(new IOService());
     HttpClient client(io_service, false);
     auto remote_config = config_->getFailoverPeerConfig();
     bool updates_successful = true;
@@ -2574,7 +2573,7 @@ HAService::sendLeaseUpdatesFromBacklog() {
 
     asyncSendLeaseUpdatesFromBacklog(client, remote_config,
                                      [&](const bool success, const std::string&, const int) {
-        io_service.stop();
+        io_service->stop();
         updates_successful = success;
     });
 
@@ -2582,7 +2581,7 @@ HAService::sendLeaseUpdatesFromBacklog() {
     Stopwatch stopwatch;
 
     // Run the IO service until it is stopped by the callback. This makes it synchronous.
-    io_service.run();
+    io_service->run();
 
     // End measuring duration.
     stopwatch.stop();
@@ -2652,19 +2651,19 @@ HAService::asyncSendHAReset(HttpClient& http_client,
 
 bool
 HAService::sendHAReset() {
-    IOService io_service;
+    IOServicePtr io_service(new IOService());
     HttpClient client(io_service, false);
     auto remote_config = config_->getFailoverPeerConfig();
     bool reset_successful = true;
 
     asyncSendHAReset(client, remote_config,
                      [&](const bool success, const std::string&, const int) {
-        io_service.stop();
+        io_service->stop();
         reset_successful = success;
     });
 
     // Run the IO service until it is stopped by the callback. This makes it synchronous.
-    io_service.run();
+    io_service->run();
 
     return (reset_successful);
 }
@@ -2756,7 +2755,7 @@ HAService::processMaintenanceStart() {
     // to know the type of the expected response.
     HttpResponseJsonPtr response = boost::make_shared<HttpResponseJson>();
 
-    IOService io_service;
+    IOServicePtr io_service(new IOService());
     HttpClient client(io_service, false);
 
     boost::system::error_code captured_ec;
@@ -2773,7 +2772,7 @@ HAService::processMaintenanceStart() {
              const HttpResponsePtr& response,
              const std::string& error_str) {
 
-             io_service.stop();
+             io_service->stop();
 
              // There are three possible groups of errors. One is the IO error
              // causing issues in communication with the peer. Another one is
@@ -2823,7 +2822,7 @@ HAService::processMaintenanceStart() {
 
     // Run the IO service until it is stopped by any of the callbacks. This
     // makes it synchronous.
-    io_service.run();
+    io_service->run();
 
     // If there was a communication problem with the partner we assume that
     // the partner is already down while we receive this command.
@@ -2883,7 +2882,7 @@ HAService::processMaintenanceCancel() {
     // to know the type of the expected response.
     HttpResponseJsonPtr response = boost::make_shared<HttpResponseJson>();
 
-    IOService io_service;
+    IOServicePtr io_service(new IOService());
     HttpClient client(io_service, false);
 
     std::string error_message;
@@ -2897,7 +2896,7 @@ HAService::processMaintenanceCancel() {
              const HttpResponsePtr& response,
              const std::string& error_str) {
 
-             io_service.stop();
+             io_service->stop();
 
              // Handle first two groups of errors.
              if (ec || !error_str.empty()) {
@@ -2937,7 +2936,7 @@ HAService::processMaintenanceCancel() {
 
     // Run the IO service until it is stopped by any of the callbacks. This
     // makes it synchronous.
-    io_service.run();
+    io_service->run();
 
     // There was an error in communication with the partner or the
     // partner was unable to revert its state.
index dd6507cc58c291d6b2dda17a31abc327ffa50633..2840f5806552b57bc9ecc4cdf45c5efac568a35c 100644 (file)
@@ -594,15 +594,15 @@ public:
           factory_(new TestHttpResponseCreatorFactory()),
           factory2_(new TestHttpResponseCreatorFactory()),
           factory3_(new TestHttpResponseCreatorFactory()),
-          listener_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+          listener_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
                                      SERVER_PORT, TlsContextPtr(), factory_,
                                      HttpListener::RequestTimeout(REQUEST_TIMEOUT),
                                      HttpListener::IdleTimeout(IDLE_TIMEOUT))),
-          listener2_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+          listener2_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
                                       SERVER_PORT + 1, TlsContextPtr(), factory2_,
                                       HttpListener::RequestTimeout(REQUEST_TIMEOUT),
                                       HttpListener::IdleTimeout(IDLE_TIMEOUT))),
-          listener3_(new HttpListener(*io_service_, IOAddress(SERVER_ADDRESS),
+          listener3_(new HttpListener(io_service_, IOAddress(SERVER_ADDRESS),
                                       SERVER_PORT + 2, TlsContextPtr(), factory3_,
                                       HttpListener::RequestTimeout(REQUEST_TIMEOUT),
                                       HttpListener::IdleTimeout(IDLE_TIMEOUT))),
index f61dbcc61f1879981e43e8bba496e6ff8ac1220c..b7c43fea49d837d6b708beae99fdcd6c13ebc064 100644 (file)
@@ -72,7 +72,7 @@ HATest::startHAService() {
 void
 HATest::runIOService(long ms) {
     io_service_->restart();
-    IntervalTimer timer(*io_service_);
+    IntervalTimer timer(io_service_);
     timer.setup(std::bind(&IOService::stop, io_service_), ms,
                 IntervalTimer::ONE_SHOT);
     io_service_->run();
@@ -82,7 +82,7 @@ HATest::runIOService(long ms) {
 void
 HATest::runIOService(long ms, std::function<bool()> stop_condition) {
     io_service_->restart();
-    IntervalTimer timer(*io_service_);
+    IntervalTimer timer(io_service_);
     bool timeout = false;
     timer.setup(std::bind(&HATest::stopIOServiceHandler, this, std::ref(timeout)),
                 ms, IntervalTimer::ONE_SHOT);
index dd6632ffdd6d74390fef6681227dee98179060fd..df8cf1856536bdadb461109c168cd3b01a02ce04 100644 (file)
@@ -55,17 +55,17 @@ const int DBG_ALL = DBGLVL_TRACE_DETAIL + 20;
 /// want keep the same data).  Organising the data in this way keeps copying to
 /// a minimum.
 struct IOFetchData {
-
+    IOServicePtr io_service_;                ///< The IO service
     // The first two members are shared pointers to a base class because what is
     // actually instantiated depends on whether the fetch is over UDP or TCP,
     // which is not known until construction of the IOFetch.  Use of a shared
     // pointer here is merely to ensure deletion when the data object is deleted.
-    boost::scoped_ptr<IOAsioSocket<IOFetch> > socket;
+    boost::scoped_ptr<IOAsioSocket<IOFetch>> socket;
                                              ///< Socket to use for I/O
     boost::scoped_ptr<IOEndpoint> remote_snd;///< Where the fetch is sent
     boost::scoped_ptr<IOEndpoint> remote_rcv;///< Where the response came from
-    OutputBufferPtr   msgbuf;      ///< Wire buffer for question
-    OutputBufferPtr   received;    ///< Received data put here
+    OutputBufferPtr   msgbuf;                ///< Wire buffer for question
+    OutputBufferPtr   received;              ///< Received data put here
     IOFetch::Callback*          callback;    ///< Called on I/O Completion
     boost::asio::deadline_timer timer;       ///< Timer to measure timeouts
     IOFetch::Protocol           protocol;    ///< Protocol being used
@@ -103,14 +103,14 @@ struct IOFetchData {
     /// \param wait Timeout for the fetch (in ms).
     ///
     /// TODO: May need to alter constructor (see comment 4 in Trac ticket #554)
-    IOFetchData(IOFetch::Protocol proto, IOService& service,
+    IOFetchData(IOFetch::Protocol proto, const IOServicePtr& service,
         const IOAddress& address, uint16_t port, OutputBufferPtr& buff,
-        IOFetch::Callback* cb, int wait) :
+        IOFetch::Callback* cb, int wait) : io_service_(service),
         socket((proto == IOFetch::UDP) ?
             static_cast<IOAsioSocket<IOFetch>*>(
-                new UDPSocket<IOFetch>(service)) :
+                new UDPSocket<IOFetch>(io_service_)) :
             static_cast<IOAsioSocket<IOFetch>*>(
-                new TCPSocket<IOFetch>(service))
+                new TCPSocket<IOFetch>(io_service_))
             ),
         remote_snd((proto == IOFetch::UDP) ?
             static_cast<IOEndpoint*>(new UDPEndpoint(address, port)) :
@@ -123,7 +123,7 @@ struct IOFetchData {
         msgbuf(new OutputBuffer(512)),
         received(buff),
         callback(cb),
-        timer(service.getInternalIOService()),
+        timer(io_service_->getInternalIOService()),
         protocol(proto),
         cumulative(0),
         expected(0),
@@ -151,7 +151,7 @@ struct IOFetchData {
 
 /// IOFetch Constructor - just initialize the private data
 
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
     const isc::dns::Question& question, const IOAddress& address,
     uint16_t port, OutputBufferPtr& buff, Callback* cb, int wait, bool edns) {
     MessagePtr query_msg(new Message(Message::RENDER));
@@ -159,7 +159,7 @@ IOFetch::IOFetch(Protocol protocol, IOService& service,
                 cb, wait, edns);
 }
 
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
     OutputBufferPtr& outpkt, const IOAddress& address, uint16_t port,
     OutputBufferPtr& buff, Callback* cb, int wait) :
     data_(new IOFetchData(protocol, service,
@@ -168,7 +168,7 @@ IOFetch::IOFetch(Protocol protocol, IOService& service,
     data_->packet = true;
 }
 
-IOFetch::IOFetch(Protocol protocol, IOService& service,
+IOFetch::IOFetch(Protocol protocol, const IOServicePtr& service,
     ConstMessagePtr query_message, const IOAddress& address, uint16_t port,
     OutputBufferPtr& buff, Callback* cb, int wait) {
     MessagePtr msg(new Message(Message::RENDER));
@@ -185,7 +185,7 @@ IOFetch::IOFetch(Protocol protocol, IOService& service,
 
 void
 IOFetch::initIOFetch(MessagePtr& query_msg, Protocol protocol,
-                     IOService& service,
+                     const IOServicePtr& service,
                      const isc::dns::Question& question,
                      const IOAddress& address, uint16_t port,
                      OutputBufferPtr& buff, Callback* cb, int wait, bool edns) {
index 4b247abfa462d3dad930c8f71a8181f2689d346e..fea13e0455cbc40f008513f13fa1a50c9457b657 100644 (file)
@@ -132,7 +132,7 @@ public:
     ///        -1 indicates no timeout.
     /// \param edns true if the request should be EDNS. The default value is
     ///        true.
-    IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+    IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
             const isc::dns::Question& question,
             const isc::asiolink::IOAddress& address,
             uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
@@ -159,7 +159,7 @@ public:
     ///        and deleting it if necessary.
     /// \param wait Timeout for the fetch (in ms).  The default value of
     ///        -1 indicates no timeout.
-    IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+    IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
             isc::dns::ConstMessagePtr query_message,
             const isc::asiolink::IOAddress& address,
             uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
@@ -184,7 +184,7 @@ public:
     /// (default = 53)
     /// \param wait Timeout for the fetch (in ms).  The default value of
     ///     -1 indicates no timeout.
-    IOFetch(Protocol protocol, isc::asiolink::IOService& service,
+    IOFetch(Protocol protocol, const isc::asiolink::IOServicePtr& service,
             isc::util::OutputBufferPtr& outpkt,
             const isc::asiolink::IOAddress& address,
             uint16_t port, isc::util::OutputBufferPtr& buff, Callback* cb,
@@ -218,7 +218,7 @@ private:
     /// parameter "query_message"
     /// \param query_message the message to be sent out.
     void initIOFetch(isc::dns::MessagePtr& query_message, Protocol protocol,
-                     isc::asiolink::IOService& service,
+                     const isc::asiolink::IOServicePtr& service,
                      const isc::dns::Question& question,
                      const isc::asiolink::IOAddress& address, uint16_t port,
                      isc::util::OutputBufferPtr& buff, Callback* cb, int wait,
index 6529c356ba014e435e0921571e3036786f147a41..5bab99f6a3884913a41e521314e21ad8fc846ded 100644 (file)
@@ -55,7 +55,7 @@ const bool DEBUG = false;
 class IOFetchTest : public virtual ::testing::Test, public virtual IOFetch::Callback
 {
 public:
-    IOService       service_;       ///< Service to run the query
+    IOServicePtr    service_;       ///< Service to run the query
     IOFetch::Result expected_;      ///< Expected result of the callback
     bool            run_;           ///< Did the callback run already?
     Question        question_;      ///< What to ask
@@ -88,7 +88,7 @@ public:
 
     /// \brief Constructor
     IOFetchTest() :
-        service_(),
+        service_(new IOService()),
         expected_(IOFetch::NOTSET),
         run_(false),
         question_(Name("example.net"), RRClass::IN(), RRType::A()),
@@ -101,7 +101,7 @@ public:
                                         // Timeout interval chosen to ensure no timeout
         protocol_(IOFetch::TCP),        // for initialization - will be changed
         cumulative_(0),
-        timer_(service_.getInternalIOService()),
+        timer_(service_->getInternalIOService()),
         receive_buffer_(),
         expected_buffer_(new OutputBuffer(512)),
         send_buffer_(),
@@ -455,7 +455,7 @@ public:
         }
 
         // ... and cause the run loop to exit.
-        service_.stop();
+        service_->stop();
     }
 
     // The next set of methods are the tests themselves.  A number of the TCP
@@ -474,15 +474,15 @@ public:
         expected_ = IOFetch::STOPPED;
 
         // Post the query
-        service_.post(fetch);
+        service_->post(fetch);
 
         // Post query_.stop() (yes, the std::bind thing is just
         // query_.stop()).
-        service_.post(std::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
+        service_->post(std::bind(&IOFetch::stop, fetch, IOFetch::STOPPED));
 
         // Run both of them.  run() returns when everything in the I/O service
         // queue has completed.
-        service_.run();
+        service_->run();
         EXPECT_TRUE(run_);
     }
 
@@ -500,9 +500,9 @@ public:
 
         // Stop before it is started
         fetch.stop();
-        service_.post(fetch);
+        service_->post(fetch);
 
-        service_.run();
+        service_->run();
         EXPECT_TRUE(run_);
     }
 
@@ -516,8 +516,8 @@ public:
         protocol_ = protocol;
         expected_ = IOFetch::TIME_OUT;
 
-        service_.post(fetch);
-        service_.run();
+        service_->post(fetch);
+        service_->run();
         EXPECT_TRUE(run_);
     }
 
@@ -542,21 +542,21 @@ public:
         }
 
         // Socket into which the connection will be accepted.
-        tcp::socket socket(service_.getInternalIOService());
+        tcp::socket socket(service_->getInternalIOService());
 
         // Acceptor object - called when the connection is made, the handler
         // will initiate a read on the socket.
-        tcp::acceptor acceptor(service_.getInternalIOService(),
+        tcp::acceptor acceptor(service_->getInternalIOService(),
                                tcp::endpoint(tcp::v4(), TEST_PORT));
         acceptor.async_accept(socket,
             std::bind(&IOFetchTest::tcpAcceptHandler, this, &socket, ph::_1));
 
         // Post the TCP fetch object to send the query and receive the response.
-        service_.post(tcp_fetch_);
+        service_->post(tcp_fetch_);
 
         // ... and execute all the callbacks.  This exits when the fetch
         // completes.
-        service_.run();
+        service_->run();
         EXPECT_TRUE(run_);  // Make sure the callback did execute
 
         // Tidy up
@@ -574,7 +574,7 @@ public:
         protocol_ = IOFetch::UDP;
 
         // Set up the server.
-        udp::socket socket(service_.getInternalIOService(), udp::v4());
+        udp::socket socket(service_->getInternalIOService(), udp::v4());
         socket.set_option(socket_base::reuse_address(true));
         socket.bind(udp::endpoint(TEST_HOST, TEST_PORT));
         return_data_ = "Message returned to the client";
@@ -586,12 +586,12 @@ public:
                                   std::bind(&IOFetchTest::udpReceiveHandler,
                                             this, &remote, &socket,
                                             ph::_1, ph::_2, bad_qid, second_send));
-        service_.post(udp_fetch_);
+        service_->post(udp_fetch_);
         if (debug_) {
             cout << "udpSendReceive: async_receive_from posted,"
                 "waiting for callback" << endl;
         }
-        service_.run();
+        service_->run();
 
         socket.close();
 
index 45dcfa8630bda517e8d7f20913b2cda8b78d3332..5c74d2702a83f6c89d6933887bf22c21bc52d3d8 100644 (file)
@@ -107,9 +107,9 @@ typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
 /// @note The caller must not provide a null pointer to the TLS context.
 template <typename Callback, typename TlsStreamImpl>
 TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
-    : TlsStreamImpl(service.getInternalIOService(), context->getContext()),
-      role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+    : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+      context->getContext()), role_(context->getRole()) {
 }
 
 /// @brief Botan boost ASIO TLS stream.
@@ -128,7 +128,7 @@ public:
     /// @param service I/O Service object used to manage the stream.
     /// @param context Pointer to the TLS context.
     /// @note The caller must not provide a null pointer to the TLS context.
-    TlsStream(IOService& service, TlsContextPtr context)
+    TlsStream(const IOServicePtr& service, TlsContextPtr context)
         : Base(service, context) {
     }
 
index 0a9b3b16c637f7132ff609834a545872be9abf9b..df0ad33767b029f7bf5961f96eedb6b750c3b774 100644 (file)
@@ -95,8 +95,9 @@ typedef boost::asio::ip::tcp::socket TlsStreamImpl;
 /// @note The caller must not provide a null pointer to the TLS context.
 template <typename Callback, typename TlsStreamImpl>
 TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
-    : TlsStreamImpl(service.getInternalIOService()), role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+    : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService()),
+      role_(context->getRole()) {
 }
 
 /// @brief Botan fake TLS stream.
@@ -114,7 +115,7 @@ public:
     /// @param service I/O Service object used to manage the stream.
     /// @param context Pointer to the TLS context.
     /// @note The caller must not provide a null pointer to the TLS context.
-    TlsStream(IOService& service, TlsContextPtr context)
+    TlsStream(const IOServicePtr& service, TlsContextPtr context)
         : Base(service, context) {
     }
 
index b119760ebf45c7e5a9c31e10f4cfc82f7da5621c..87306d917140ae169ff0443a987b48058cef89c2 100644 (file)
@@ -118,12 +118,22 @@ public:
     TlsRole role_;
 };
 
+class StreamService {
+public:
+    /// @brief Constructor.
+    StreamService(const IOServicePtr& io_service) : io_service_(io_service) {
+    }
+private:
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+};
+
 /// @brief TLS stream base class.
 ///
 /// @tparam Callback The type of callbacks.
 /// @tparam TlsStreamImpl The type of underlying TLS streams.
 template <typename Callback, typename TlsStreamImpl>
-class TlsStreamBase : public TlsStreamImpl {
+class TlsStreamBase : public StreamService, public TlsStreamImpl {
 public:
 
     /// @brief Constructor.
@@ -131,7 +141,7 @@ public:
     /// @param service I/O Service object used to manage the stream.
     /// @param context Pointer to the TLS context.
     /// @note The caller must not provide a null pointer to the TLS context.
-    TlsStreamBase(IOService& service, TlsContextPtr context);
+    TlsStreamBase(const IOServicePtr& service, TlsContextPtr context);
 
     /// @brief Destructor.
     virtual ~TlsStreamBase() { }
index 72aafe3f796cbf664a609df2cff5b03bd07e4c21..6226bf1e289a4a07535fe1415542cdb3b6c19605 100644 (file)
@@ -40,7 +40,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service The IO service used to handle events.
-    IntervalTimerImpl(IOService& io_service);
+    IntervalTimerImpl(const IOServicePtr& io_service);
 
     /// @brief Destructor.
     ~IntervalTimerImpl();
@@ -85,6 +85,9 @@ private:
     /// @brief The interval in milliseconds.
     std::atomic<long> interval_;
 
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+
     /// @brief The asio timer.
     boost::asio::deadline_timer timer_;
 
@@ -101,8 +104,8 @@ private:
     static const long INVALIDATED_INTERVAL = -1;
 };
 
-IntervalTimerImpl::IntervalTimerImpl(IOService& io_service) :
-    interval_(0), timer_(io_service.getInternalIOService()),
+IntervalTimerImpl::IntervalTimerImpl(const IOServicePtr& io_service) :
+    interval_(0), io_service_(io_service), timer_(io_service_->getInternalIOService()),
     mode_(IntervalTimer::REPEATING) {
 }
 
@@ -173,7 +176,7 @@ IntervalTimerImpl::callback(const boost::system::error_code& ec) {
     }
 }
 
-IntervalTimer::IntervalTimer(IOService& io_service) :
+IntervalTimer::IntervalTimer(const IOServicePtr& io_service) :
     impl_(new IntervalTimerImpl(io_service)) {
 }
 
index 5dc8b71ab3447f160eeefe36d5233149b1522361..0475abcadc5654e84761eadaf7c52eb326fd6e78 100644 (file)
@@ -79,8 +79,8 @@ public:
     /// memory allocation fails inside the method.
     /// This constructor may also throw \c boost::system::system_error.
     ///
-    /// \param io_service A reference to an instance of IOService
-    IntervalTimer(IOService& io_service);
+    /// \param io_service A smart pointer to an instance of IOService
+    IntervalTimer(const IOServicePtr& io_service);
 
     /// \brief The destructor.
     ///
index d08bf39d9b469c3d0df0794ecfc21f44eba44642..9454ea010d2bf487cd532d97585862d0ddb59c5e 100644 (file)
@@ -37,9 +37,9 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service Reference to the IO service.
-    explicit IOAcceptor(IOService& io_service)
-        : IOSocket(),
-          acceptor_(new typename ProtocolType::acceptor(io_service.getInternalIOService())) {
+    explicit IOAcceptor(const IOServicePtr& io_service)
+        : IOSocket(), io_service_(io_service),
+          acceptor_(new typename ProtocolType::acceptor(io_service_->getInternalIOService())) {
     }
 
     /// @brief Destructor.
@@ -123,13 +123,14 @@ protected:
         acceptor_->async_accept(socket.getASIOSocket(), callback);
     }
 
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
 
     /// @brief Underlying ASIO acceptor implementation.
     boost::shared_ptr<typename ProtocolType::acceptor> acceptor_;
 
 };
 
-
 } // end of namespace asiolink
 } // end of isc
 
index c498702324de8193e2d0cc5b1c77a18913c747df..d755af4518821b707cd7e50823cb1e37ff3264c4 100644 (file)
@@ -27,7 +27,7 @@ public:
     ///
     /// @param io_service the process IO service.
     /// @param handler the signal handler.
-    IOSignalSetImpl(IOServicePtr io_service, IOSignalHandler handler);
+    IOSignalSetImpl(const IOServicePtr& io_service, IOSignalHandler handler);
 
     /// @brief Destructor.
     ~IOSignalSetImpl();
@@ -65,7 +65,7 @@ private:
     void callback(const boost::system::error_code& ec, int signum);
 };
 
-IOSignalSetImpl::IOSignalSetImpl(IOServicePtr io_service,
+IOSignalSetImpl::IOSignalSetImpl(const IOServicePtr& io_service,
                                  IOSignalHandler handler)
     : io_service_(io_service),
       signal_set_(io_service_->getInternalIOService()),
@@ -122,7 +122,7 @@ IOSignalSetImpl::remove(int signum) {
     }
 }
 
-IOSignalSet::IOSignalSet(IOServicePtr io_service, IOSignalHandler handler) :
+IOSignalSet::IOSignalSet(const IOServicePtr& io_service, IOSignalHandler handler) :
     impl_(new IOSignalSetImpl(io_service, handler)) {
     // It can throw but the error is fatal...
     impl_->install();
index 8fbcbe1660489b7f790ac410e414c1d7ae6893fa..57db9906d40f63f94e16edc34a13661709e93395 100644 (file)
@@ -29,7 +29,7 @@ public:
     ///
     /// @param io_service IOService to which to send the signal.
     /// @param handler Handler to call when a signal is received.
-    IOSignalSet(asiolink::IOServicePtr io_service, IOSignalHandler handler);
+    IOSignalSet(const asiolink::IOServicePtr& io_service, IOSignalHandler handler);
 
     /// @brief Destructor.
     ~IOSignalSet();
index a558fd1044c54ab407da8e4140161e8fcebecbc7..957d9e5ad2e67f01a5fdf848188454b07a5edb81 100644 (file)
@@ -117,9 +117,9 @@ typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
 /// @note The caller must not provide a null pointer to the TLS context.
 template <typename Callback, typename TlsStreamImpl>
 TlsStreamBase<Callback, TlsStreamImpl>::
-TlsStreamBase(IOService& service, TlsContextPtr context)
-    : TlsStreamImpl(service.getInternalIOService(), context->getContext()),
-      role_(context->getRole()) {
+TlsStreamBase(const IOServicePtr& io_service, TlsContextPtr context)
+    : StreamService(io_service), TlsStreamImpl(io_service->getInternalIOService(),
+      context->getContext()), role_(context->getRole()) {
 }
 
 /// @brief OpenSSL TLS stream.
@@ -137,7 +137,7 @@ public:
     /// @param service I/O Service object used to manage the stream.
     /// @param context Pointer to the TLS context.
     /// @note The caller must not provide a null pointer to the TLS context.
-    TlsStream(IOService& service, TlsContextPtr context)
+    TlsStream(const IOServicePtr& service, TlsContextPtr context)
         : Base(service, context) {
     }
 
index 4fab1ddbbe8bf7a1c6c9f04a6b9ad7ad53bb6b17..58296d86c18a932bbb07b4c22dfe202d4530830d 100644 (file)
@@ -35,7 +35,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service IO service.
-    explicit TCPAcceptor(IOService& io_service)
+    explicit TCPAcceptor(const IOServicePtr& io_service)
         : IOAcceptor<boost::asio::ip::tcp, C>(io_service) {
     }
 
index 40a53bec968dede77b6b6384138b616f430ab3eb..c2e70fcfe9c6083b51826911366ab9c3a96a6c59 100644 (file)
@@ -68,7 +68,7 @@ public:
     /// socket.  In this case, the open() and close() methods are used.
     ///
     /// \param service I/O Service object used to manage the socket.
-    TCPSocket(IOService& service);
+    TCPSocket(const IOServicePtr& service);
 
     /// \brief Destructor
     virtual ~TCPSocket();
@@ -222,6 +222,10 @@ public:
     }
 
 private:
+
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+
     /// Two variables to hold the socket - a socket and a pointer to it.  This
     /// handles the case where a socket is passed to the TCPSocket on
     /// construction, or where it is asked to manage its own socket.
@@ -261,8 +265,8 @@ TCPSocket<C>::TCPSocket(boost::asio::ip::tcp::socket& socket) :
 // Constructor - create socket on the fly
 
 template <typename C>
-TCPSocket<C>::TCPSocket(IOService& service) :
-    socket_ptr_(new boost::asio::ip::tcp::socket(service.getInternalIOService())),
+TCPSocket<C>::TCPSocket(const IOServicePtr& io_service) : io_service_(io_service),
+    socket_ptr_(new boost::asio::ip::tcp::socket(io_service_->getInternalIOService())),
     socket_(*socket_ptr_)
 {
 }
index c875b06a667ff5785309128afe7dc5c5fbd86ca4..b2cd459ac158061cd8261398853111c413ca9f43 100644 (file)
@@ -25,7 +25,7 @@ using namespace isc::asiolink;
 class IntervalTimerTest : public ::testing::Test {
 protected:
     IntervalTimerTest() :
-        io_service_(), timer_called_(false), timer_cancel_success_(false)
+        io_service_(new IOService()), timer_called_(false), timer_cancel_success_(false)
     {}
     ~IntervalTimerTest() {}
     class TimerCallBack {
@@ -33,7 +33,7 @@ protected:
         TimerCallBack(IntervalTimerTest* test_obj) : test_obj_(test_obj) {}
         void operator()() const {
             test_obj_->timer_called_ = true;
-            test_obj_->io_service_.stop();
+            test_obj_->io_service_->stop();
             return;
         }
     private:
@@ -72,7 +72,7 @@ protected:
             } else if (count_ == 2) {
                 // Second time of call back.
                 // Stop io_service to stop all timers.
-                test_obj_->io_service_.stop();
+                test_obj_->io_service_->stop();
                 // Compare the value of counter_.counter_ with stored one.
                 // If TimerCallBackCounter was not called (expected behavior),
                 // they are same.
@@ -119,7 +119,7 @@ protected:
                 // Second time of call back.
                 // If it reaches here, re-setup() is failed (unexpected).
                 // We should stop here.
-                test_obj_->io_service_.stop();
+                test_obj_->io_service_->stop();
             }
             return;
         }
@@ -143,7 +143,7 @@ protected:
         int& counter_;
     };
 protected:
-    IOService io_service_;
+    IOServicePtr io_service_;
     bool timer_called_;
     bool timer_cancel_success_;
 };
@@ -169,7 +169,7 @@ TEST_F(IntervalTimerTest, startIntervalTimer) {
     // setup timer
     itimer.setup(TimerCallBack(this), 100);
     EXPECT_EQ(100, itimer.getInterval());
-    io_service_.run();
+    io_service_->run();
     // Control reaches here after io_service_ was stopped by TimerCallBack.
 
     // delta: difference between elapsed time and 100 milliseconds.
@@ -226,7 +226,7 @@ TEST_F(IntervalTimerTest, destructIntervalTimer) {
     itimer_canceller.setup(
         TimerCallBackCancelDeleter(this, itimer_counter, callback_canceller),
         300);
-    io_service_.run();
+    io_service_->run();
     EXPECT_TRUE(timer_cancel_success_);
 }
 
@@ -238,7 +238,7 @@ TEST_F(IntervalTimerTest, cancel) {
     unsigned int counter = 0;
     itimer_counter.setup(TimerCallBackCanceller(counter, itimer_counter), 100);
     itimer_watcher.setup(TimerCallBack(this), 200);
-    io_service_.run();
+    io_service_->run();
     EXPECT_EQ(1, counter);
     EXPECT_EQ(0, itimer_counter.getInterval());
 
@@ -255,7 +255,7 @@ TEST_F(IntervalTimerTest, overwriteIntervalTimer) {
     //     - increments internal counter in callback function
     //       (TimerCallBackCounter)
     //       interval: 300 milliseconds
-    //     - io_service_.stop() (TimerCallBack)
+    //     - io_service_->stop() (TimerCallBack)
     //       interval: 100 milliseconds
     //  itimer_overwriter (B)
     //   (Calls TimerCallBackOverwriter)
@@ -281,7 +281,7 @@ TEST_F(IntervalTimerTest, overwriteIntervalTimer) {
     start = boost::posix_time::microsec_clock::universal_time();
     itimer.setup(TimerCallBackCounter(this), 300);
     itimer_overwriter.setup(TimerCallBackOverwriter(this, itimer), 400);
-    io_service_.run();
+    io_service_->run();
     // Control reaches here after io_service_ was stopped by
     // TimerCallBackCounter or TimerCallBackOverwriter.
 
@@ -314,7 +314,7 @@ TEST_F(IntervalTimerTest, intervalModeTest) {
     // we've hit our goals.  It won't return zero unless is out of
     // work or the service has been stopped by the test timer.
     int cnt = 0;
-    while (((cnt = io_service_.runOne()) > 0) && (repeater_count < 5)) {
+    while (((cnt = io_service_->runOne()) > 0) && (repeater_count < 5)) {
         // deliberately empty
     };
 
@@ -341,7 +341,7 @@ TEST_F(IntervalTimerTest, timerReuseTest) {
 
     // Run until a single event handler executes.  This should be our
     // one-shot expiring.
-    io_service_.runOne();
+    io_service_->runOne();
 
     // Verify the timer expired once.
     ASSERT_EQ(one_shot_count, 1);
@@ -351,7 +351,7 @@ TEST_F(IntervalTimerTest, timerReuseTest) {
 
     // Run until a single event handler executes.  This should be our
     // one-shot expiring.
-    io_service_.runOne();
+    io_service_->runOne();
 
     // Verify the timer expired once.
     ASSERT_EQ(one_shot_count, 2);
@@ -363,7 +363,7 @@ TEST_F(IntervalTimerTest, timerReuseTest) {
     // we've hit our goals.  It won't return zero unless is out of
     // work or the service has been stopped by the test timer.
     int cnt = 0;
-    while ((cnt = io_service_.runOne()) && (one_shot_count < 4)) {
+    while ((cnt = io_service_->runOne()) && (one_shot_count < 4)) {
         // deliberately empty
     };
 
index 26e3dc8cdd4801f1c166b91dc0f20a9e9b8f71c8..721172b6abe3670613dfe4e817dea153537dec6e 100644 (file)
@@ -50,9 +50,9 @@ public:
 
     /// @brief Constructor.
     IOSignalTest() :
-        io_service_(new asiolink::IOService()), test_timer_(*io_service_),
-        test_time_ms_(0), io_signal_set_(),
-        processed_signals_(), stop_at_count_(0), handler_throw_error_(false) {
+        io_service_(new asiolink::IOService()), test_timer_(io_service_),
+        test_time_ms_(0), io_signal_set_(), processed_signals_(), stop_at_count_(0),
+        handler_throw_error_(false) {
 
         io_signal_set_.reset(new IOSignalSet(io_service_,
                                              std::bind(&IOSignalTest::processSignal,
@@ -118,7 +118,7 @@ TEST_F(IOSignalTest, singleSignalTest) {
     ASSERT_NO_THROW(io_signal_set_->add(SIGINT));
 
     // Use TimedSignal to generate SIGINT 100 ms after we start IOService::run.
-    TimedSignal sig_int(*io_service_, SIGINT, 100);
+    TimedSignal sig_int(io_service_, SIGINT, 100);
 
     // The first handler executed is the IOSignal's internal timer expire
     // callback.
@@ -143,7 +143,7 @@ TEST_F(IOSignalTest, singleSignalTest) {
     ASSERT_NO_THROW(io_signal_set_->remove(SIGINT));
 
     // Use TimedSignal to generate SIGINT 100 ms after we start IOService::run.
-    TimedSignal sig_int_too_late(*io_service_, SIGINT, 100);
+    TimedSignal sig_int_too_late(io_service_, SIGINT, 100);
 
     // The first handler executed is the IOSignal's internal timer expire
     // callback.
@@ -174,7 +174,7 @@ TEST_F(IOSignalTest, hammer) {
 
     // User a repeating TimedSignal so we should generate a signal every 1 ms
     // until we hit our stop count.
-    TimedSignal sig_int(*io_service_, SIGINT, 1,
+    TimedSignal sig_int(io_service_, SIGINT, 1,
                         asiolink::IntervalTimer::REPEATING);
 
     // Start processing IO.  This should continue until we stop either by
@@ -203,7 +203,7 @@ TEST_F(IOSignalTest, handlerThrow) {
     stop_at_count_ = 1;
 
     // Use TimedSignal to generate SIGINT after we start IOService::run.
-    TimedSignal sig_int(*io_service_, SIGINT, 100,
+    TimedSignal sig_int(io_service_, SIGINT, 100,
                         asiolink::IntervalTimer::REPEATING);
 
     // Set the test flag to cause the handler to throw an exception.
@@ -235,14 +235,14 @@ TEST_F(IOSignalTest, mixedSignals) {
     // Since signal order arrival cannot be guaranteed, we'll use
     // explicit one shot signals so we can guarantee how many
     // of each signal we should get.
-    TimedSignal sig1(*io_service_, SIGINT, 2);
-    TimedSignal sig2(*io_service_, SIGUSR1, 2);
-    TimedSignal sig3(*io_service_, SIGINT, 2);
-    TimedSignal sig4(*io_service_, SIGUSR2, 2);
-    TimedSignal sig5(*io_service_, SIGINT, 2);
-    TimedSignal sig6(*io_service_, SIGUSR1, 2);
-    TimedSignal sig7(*io_service_, SIGINT, 2);
-    TimedSignal sig8(*io_service_, SIGUSR2, 2);
+    TimedSignal sig1(io_service_, SIGINT, 2);
+    TimedSignal sig2(io_service_, SIGUSR1, 2);
+    TimedSignal sig3(io_service_, SIGINT, 2);
+    TimedSignal sig4(io_service_, SIGUSR2, 2);
+    TimedSignal sig5(io_service_, SIGINT, 2);
+    TimedSignal sig6(io_service_, SIGUSR1, 2);
+    TimedSignal sig7(io_service_, SIGINT, 2);
+    TimedSignal sig8(io_service_, SIGUSR2, 2);
 
     // Start processing IO.  This should continue until we stop either by
     // hitting the stop count or if things go wrong, max test time.
index 76706543f063813d28c0e831b3d69bdf215452ee..ea7d386bbbe0aeeafd07cc93ee4f08f64d55313f 100644 (file)
@@ -54,7 +54,7 @@ public:
 
     /// @brief Constructor.
     ProcessSpawnTest() :
-        io_service_(getIOService()), test_timer_(*io_service_),
+        io_service_(getIOService()), test_timer_(io_service_),
         test_time_ms_(0), io_signal_set_(), processed_signals_() {
 
         io_signal_set_.reset(new IOSignalSet(io_service_,
index 8a4ed06656da3e44c7a0a9b64653483c163595d0..5ca4eebcd3ff284b2ae491cc2c6843f0b65edde2 100644 (file)
@@ -64,8 +64,8 @@ public:
     /// connect() to connect to the server.
     ///
     /// @param io_service IO service to be stopped on error.
-    explicit TCPClient(IOService& io_service)
-        : io_service_(io_service.getInternalIOService()), socket_(io_service_) {
+    explicit TCPClient(const IOServicePtr& io_service)
+        : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
     }
 
     /// @brief Destructor.
@@ -105,7 +105,7 @@ public:
             if (ec.value() != boost::asio::error::in_progress) {
                 ADD_FAILURE() << "error occurred while connecting: "
                               << ec.message();
-                io_service_.stop();
+                io_service_->stop();
             }
         }
     }
@@ -117,8 +117,8 @@ public:
 
 private:
 
-    /// @brief Holds reference to the IO service.
-    boost::asio::io_service& io_service_;
+    /// @brief Holds the IO service.
+    IOServicePtr io_service_;
 
     /// @brief A socket used for the connection.
     boost::asio::ip::tcp::socket socket_;
@@ -148,7 +148,7 @@ public:
     /// @param acceptor Reference to the TCP acceptor on which asyncAccept
     /// will be called.
     /// @param callback Callback function for the asyncAccept.
-    explicit Acceptor(IOService& io_service, TestTCPAcceptor& acceptor,
+    explicit Acceptor(const IOServicePtr& io_service, TestTCPAcceptor& acceptor,
                       const TCPAcceptorCallback& callback)
         : socket_(io_service), acceptor_(acceptor), callback_(callback) {
     }
@@ -201,7 +201,7 @@ public:
     /// against endlessly running IO service when TCP connections are
     /// unsuccessful.
     TCPAcceptorTest()
-        : io_service_(), acceptor_(io_service_),
+        : io_service_(new IOService()), acceptor_(io_service_),
           asio_endpoint_(boost::asio::ip::address::from_string(SERVER_ADDRESS),
                          SERVER_PORT),
           endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
@@ -284,12 +284,12 @@ public:
             } else {
                 ++aborted_connections_num_;
             }
-            io_service_.stop();
+            io_service_->stop();
         }
 
         // We have reached the maximum number of connections - end the test.
         if (++connections_num_ >= max_connections_) {
-            io_service_.stop();
+            io_service_->stop();
             return;
         }
 
@@ -301,11 +301,11 @@ public:
     /// It stops the IO service and reports test timeout.
     void timeoutHandler() {
         ADD_FAILURE() << "Timeout occurred while running the test!";
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief IO service.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief TCPAcceptor under test.
     TestTCPAcceptor acceptor_;
@@ -355,7 +355,7 @@ TEST_F(TCPAcceptorTest, asyncAccept) {
 
     // Run the IO service until we have accepted 10 connections, an error
     // or test timeout occurred.
-    io_service_.run();
+    io_service_->run();
 
     // Make sure that all accepted connections have been recorded.
     EXPECT_EQ(10, connections_num_);
@@ -431,7 +431,7 @@ TEST_F(TCPAcceptorTest, close) {
     acceptor_.close();
 
     // Run the IO service.
-    io_service_.run();
+    io_service_->run();
 
     // The connections should have been aborted.
     EXPECT_EQ(1, connections_num_);
index 370d71d45514ad00c44dd4f729b031598e67d538..b5b2c6e9d69f1a2fc3640d27aebc67aeef8f3406 100644 (file)
@@ -234,7 +234,7 @@ serverRead(tcp::socket& socket, TCPCallback& server_cb) {
 TEST(TCPSocket, processReceivedData) {
     const uint16_t PACKET_SIZE = 16382;     // Amount of "real" data in the buffer
 
-    IOService               service;        // Used to instantiate socket
+    IOServicePtr            service(new IOService);   // Used to instantiate socket
     TCPSocket<TCPCallback>  test(service);  // Socket under test
     uint8_t                 inbuff[PACKET_SIZE + 2];   // Buffer to check
     OutputBufferPtr         outbuff(new OutputBuffer(16));
@@ -308,10 +308,10 @@ TEST(TCPSocket, processReceivedData) {
 TEST(TCPSocket, sequenceTest) {
 
     // Common objects.
-    IOService   service;                    // Service object for async control
+    IOServicePtr service(new IOService());  // Service object for async control
 
     // The client - the TCPSocket being tested
-    TCPSocket<TCPCallback>  client(service);// Socket under test
+    TCPSocket<TCPCallback> client(service); // Socket under test
     TCPCallback client_cb("Client");        // Async I/O callback function
     TCPEndpoint client_remote_endpoint;     // Where client receives message from
     OutputBufferPtr client_buffer(new OutputBuffer(128));
@@ -324,7 +324,7 @@ TEST(TCPSocket, sequenceTest) {
     TCPEndpoint server_endpoint(server_address, SERVER_PORT);
                                             // Endpoint describing server
     TCPEndpoint server_remote_endpoint;     // Address where server received message from
-    tcp::socket server_socket(service.getInternalIOService());
+    tcp::socket server_socket(service->getInternalIOService());
                                             // Socket used for server
 
     // Step 1.  Create the connection between the client and the server.  Set
@@ -335,8 +335,8 @@ TEST(TCPSocket, sequenceTest) {
     server_cb.queued() = TCPCallback::ACCEPT;
     server_cb.called() = TCPCallback::NONE;
     server_cb.setCode(42);  // Some error
-    tcp::acceptor acceptor(service.getInternalIOService(),
-                            tcp::endpoint(tcp::v4(), SERVER_PORT));
+    tcp::acceptor acceptor(service->getInternalIOService(),
+                           tcp::endpoint(tcp::v4(), SERVER_PORT));
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     acceptor.async_accept(server_socket, server_cb);
 
@@ -348,8 +348,8 @@ TEST(TCPSocket, sequenceTest) {
     client.open(&server_endpoint, client_cb);
 
     // Run the open and the accept callback and check that they ran.
-    service.runOne();
-    service.runOne();
+    service->runOne();
+    service->runOne();
 
     EXPECT_EQ(TCPCallback::ACCEPT, server_cb.called());
     EXPECT_EQ(0, server_cb.getCode());
@@ -377,7 +377,7 @@ TEST(TCPSocket, sequenceTest) {
 
     // Wait for the client callback to complete. (Must do this first on
     // Solaris: if we do the synchronous read first, the test hangs.)
-    service.runOne();
+    service->runOne();
 
     // Synchronously read the data from the server.;
     serverRead(server_socket, server_cb);
@@ -442,7 +442,7 @@ TEST(TCPSocket, sequenceTest) {
     bool server_complete = false;
     bool client_complete = false;
     while (!server_complete || !client_complete) {
-        service.runOne();
+        service->runOne();
 
         // Has the server run?
         if (!server_complete) {
index f7e65e48791dfa40cda598627118c07f75b4fe9d..d04256683989cbe0689ba518b67a82ca6dc77fa8 100644 (file)
@@ -65,8 +65,8 @@ public:
     /// connect() to connect to the server.
     ///
     /// @param io_service IO service to be stopped on error.
-    explicit TLSClient(IOService& io_service)
-        : io_service_(io_service.getInternalIOService()), socket_(io_service_) {
+    explicit TLSClient(const IOServicePtr& io_service)
+        : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
     }
 
     /// @brief Destructor.
@@ -106,7 +106,7 @@ public:
             if (ec.value() != error::in_progress) {
                 ADD_FAILURE() << "error occurred while connecting: "
                               << ec.message();
-                io_service_.stop();
+                io_service_->stop();
             }
         }
     }
@@ -119,7 +119,7 @@ public:
 private:
 
     /// @brief Holds reference to the IO service.
-    io_service& io_service_;
+    IOServicePtr io_service_;
 
     /// @brief A socket used for the connection.
     ip::tcp::socket socket_;
@@ -150,11 +150,11 @@ public:
     /// @param acceptor Reference to the TLS acceptor on which asyncAccept
     /// will be called.
     /// @param callback Callback function for the asyncAccept.
-    explicit Acceptor(IOService& io_service,
+    explicit Acceptor(const IOServicePtr& io_service,
                       TlsContextPtr context,
                       TestTLSAcceptor& acceptor,
                       const TLSAcceptorCallback& callback)
-        : socket_(io_service, context), acceptor_(acceptor),
+        : io_service_(io_service), socket_(io_service_, context), acceptor_(acceptor),
           callback_(callback) {
     }
 
@@ -177,6 +177,9 @@ public:
 
 private:
 
+    /// @brief IO service used by the tests.
+    IOServicePtr io_service_;
+
     /// @brief Socket into which connection is accepted.
     TLSSocket<SocketCallback> socket_;
 
@@ -206,7 +209,7 @@ public:
     /// against endlessly running IO service when TLS connections are
     /// unsuccessful.
     TLSAcceptorTest()
-        : io_service_(), acceptor_(io_service_),
+        : io_service_(new IOService()), acceptor_(io_service_),
           asio_endpoint_(ip::address::from_string(SERVER_ADDRESS),
                          SERVER_PORT),
           endpoint_(asio_endpoint_), test_timer_(io_service_), connections_(),
@@ -290,12 +293,12 @@ public:
             } else {
                 ++aborted_connections_num_;
             }
-            io_service_.stop();
+            io_service_->stop();
         }
 
         // We have reached the maximum number of connections - end the test.
         if (++connections_num_ >= max_connections_) {
-            io_service_.stop();
+            io_service_->stop();
             return;
         }
 
@@ -307,11 +310,11 @@ public:
     /// It stops the IO service and reports test timeout.
     void timeoutHandler() {
         ADD_FAILURE() << "Timeout occurred while running the test!";
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief IO service.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief TLSAcceptor under test.
     TestTLSAcceptor acceptor_;
@@ -361,7 +364,7 @@ TEST_F(TLSAcceptorTest, asyncAccept) {
 
     // Run the IO service until we have accepted 10 connections, an error
     // or test timeout occurred.
-    io_service_.run();
+    io_service_->run();
 
     // Make sure that all accepted connections have been recorded.
     EXPECT_EQ(10, connections_num_);
@@ -437,7 +440,7 @@ TEST_F(TLSAcceptorTest, close) {
     acceptor_.close();
 
     // Run the IO service.
-    io_service_.run();
+    io_service_->run();
 
     // The connections should have been aborted.
     EXPECT_EQ(1, connections_num_);
index 0c81ec76262a661fc0435656b6095ce9f071d323..57773f69cb9e1a8796d0138174be3ed10e194641 100644 (file)
@@ -238,7 +238,7 @@ TEST(TLSSocket, processReceivedData) {
     const uint16_t PACKET_SIZE = 16382;
 
     // Used to instantiate socket
-    IOService service;
+    IOServicePtr service(new IOService());
     TlsContextPtr context(new TlsContext(CLIENT));
     // Socket under test
     TLSSocket<TLSCallback> test(service, context);
@@ -319,7 +319,7 @@ TEST(TLSSocket, sequenceTest) {
 
     // Common objects.
     // Service object for async control
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // The client - the TLSSocket being tested
     TlsContextPtr client_ctx;
@@ -344,7 +344,7 @@ TEST(TLSSocket, sequenceTest) {
     TlsContextPtr server_ctx;
     test::configServer(server_ctx);
     // Stream used for server.
-    TlsStreamImpl server(service.getInternalIOService(), server_ctx->getContext());
+    TlsStreamImpl server(service->getInternalIOService(), server_ctx->getContext());
 
     // Step 1.  Create the connection between the client and the server.  Set
     // up the server to accept incoming connections and have the client open
@@ -354,7 +354,7 @@ TEST(TLSSocket, sequenceTest) {
     server_cb.queued() = TLSCallback::ACCEPT;
     server_cb.called() = TLSCallback::NONE;
     server_cb.setCode(42);  // Some error
-    tcp::acceptor acceptor(service.getInternalIOService(),
+    tcp::acceptor acceptor(service->getInternalIOService(),
                            tcp::endpoint(tcp::v4(), SERVER_PORT));
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     acceptor.async_accept(server.lowest_layer(), server_cb);
@@ -369,7 +369,7 @@ TEST(TLSSocket, sequenceTest) {
     // Run the open and the accept callback and check that they ran.
     while ((server_cb.called() == TLSCallback::NONE) ||
            (client_cb.called() == TLSCallback::NONE)) {
-        service.runOne();
+        service->runOne();
     }
     EXPECT_EQ(TLSCallback::ACCEPT, server_cb.called());
     EXPECT_EQ(0, server_cb.getCode());
@@ -398,7 +398,7 @@ TEST(TLSSocket, sequenceTest) {
 
     while ((server_cb.called() == TLSCallback::NONE) ||
            (client_cb.called() == TLSCallback::NONE)) {
-        service.runOne();
+        service->runOne();
     }
     EXPECT_EQ(TLSCallback::HANDSHAKE, client_cb.called());
     EXPECT_EQ(0, client_cb.getCode());
@@ -419,7 +419,7 @@ TEST(TLSSocket, sequenceTest) {
     // Wait for the client callback to complete. (Must do this first on
     // Solaris: if we do the synchronous read first, the test hangs.)
     while (client_cb.called() == TLSCallback::NONE) {
-        service.runOne();
+        service->runOne();
     }
 
     // Synchronously read the data from the server.;
@@ -486,7 +486,7 @@ TEST(TLSSocket, sequenceTest) {
     bool server_complete = false;
     bool client_complete = false;
     while (!server_complete || !client_complete) {
-        service.runOne();
+        service->runOne();
 
         // Has the server run?
         if (!server_complete) {
index 68709fbff839ef7616be2238987b93bf5f4a4f6e..f57b9a47e37c018fb268c892c5832592375da448 100644 (file)
@@ -730,7 +730,7 @@ TEST(TLSTest, configureError) {
 
 // Test if we can get a stream.
 TEST(TLSTest, stream) {
-    IOService service;
+    IOServicePtr service(new IOService());
     TlsContextPtr ctx(new TlsContext(TlsRole::CLIENT));
     boost::scoped_ptr<TlsStream<TestCallback> > st;
     EXPECT_NO_THROW(st.reset(new TlsStream<TestCallback>(service, ctx)));
@@ -738,7 +738,7 @@ TEST(TLSTest, stream) {
 
 // Test what happens when handshake is forgotten.
 TEST(TLSTest, noHandshake) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -748,7 +748,7 @@ TEST(TLSTest, noHandshake) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -765,7 +765,7 @@ TEST(TLSTest, noHandshake) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -790,7 +790,7 @@ TEST(TLSTest, noHandshake) {
     TestCallback send_cb;
     async_write(client, boost::asio::buffer(send_buf), send_cb);
     while (!timeout && !send_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer1.cancel();
 
@@ -817,7 +817,7 @@ TEST(TLSTest, noHandshake) {
     TestCallback receive_cb;
     server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
     while (!timeout && !receive_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
@@ -845,7 +845,7 @@ TEST(TLSTest, noHandshake) {
 
 // Test what happens when the server was not configured.
 TEST(TLSTest, serverNotConfigured) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -855,7 +855,7 @@ TEST(TLSTest, serverNotConfigured) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -872,7 +872,7 @@ TEST(TLSTest, serverNotConfigured) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -898,7 +898,7 @@ TEST(TLSTest, serverNotConfigured) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -945,7 +945,7 @@ TEST(TLSTest, serverNotConfigured) {
 
 // Test what happens when the client was not configured.
 TEST(TLSTest, clientNotConfigured) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -955,7 +955,7 @@ TEST(TLSTest, clientNotConfigured) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -972,7 +972,7 @@ TEST(TLSTest, clientNotConfigured) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -998,7 +998,7 @@ TEST(TLSTest, clientNotConfigured) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1044,7 +1044,7 @@ TEST(TLSTest, clientNotConfigured) {
 
 // Test what happens when the client is HTTP (vs HTTPS).
 TEST(TLSTest, clientHTTPnoS) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1054,13 +1054,13 @@ TEST(TLSTest, clientHTTPnoS) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
 
     // Client part.
-    tcp::socket client(service.getInternalIOService());
+    tcp::socket client(service->getInternalIOService());
 
     // Connect to.
     client.open(tcp::v4());
@@ -1069,7 +1069,7 @@ TEST(TLSTest, clientHTTPnoS) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1099,7 +1099,7 @@ TEST(TLSTest, clientHTTPnoS) {
     client.async_send(boost::asio::buffer(send_buf), client_cb);
 
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1139,7 +1139,7 @@ TEST(TLSTest, clientHTTPnoS) {
 
 // Test what happens when the client does not use HTTP nor HTTP.
 TEST(TLSTest, unknownClient) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1149,13 +1149,13 @@ TEST(TLSTest, unknownClient) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
 
     // Client part.
-    tcp::socket client(service.getInternalIOService());
+    tcp::socket client(service->getInternalIOService());
 
     // Connect to.
     client.open(tcp::v4());
@@ -1164,7 +1164,7 @@ TEST(TLSTest, unknownClient) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1194,7 +1194,7 @@ TEST(TLSTest, unknownClient) {
     client.async_send(boost::asio::buffer(send_buf), client_cb);
 
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1230,7 +1230,7 @@ TEST(TLSTest, unknownClient) {
 
 // Test what happens when the client uses a certificate from another CA.
 TEST(TLSTest, anotherClient) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1240,7 +1240,7 @@ TEST(TLSTest, anotherClient) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1257,7 +1257,7 @@ TEST(TLSTest, anotherClient) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1283,7 +1283,7 @@ TEST(TLSTest, anotherClient) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1331,7 +1331,7 @@ TEST(TLSTest, anotherClient) {
 
 // Test what happens when the client uses a self-signed certificate.
 TEST(TLSTest, selfSigned) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1341,7 +1341,7 @@ TEST(TLSTest, selfSigned) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1358,7 +1358,7 @@ TEST(TLSTest, selfSigned) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1384,7 +1384,7 @@ TEST(TLSTest, selfSigned) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1440,7 +1440,7 @@ TEST(TLSTest, selfSigned) {
 
 // Test what happens when handshake is forgotten.
 TEST(TLSTest, noHandshakeCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1450,7 +1450,7 @@ TEST(TLSTest, noHandshakeCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1467,7 +1467,7 @@ TEST(TLSTest, noHandshakeCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1492,7 +1492,7 @@ TEST(TLSTest, noHandshakeCloseonError) {
     TestCallback send_cb(&client.lowest_layer());
     async_write(client, boost::asio::buffer(send_buf), send_cb);
     while (!timeout && !send_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer1.cancel();
 
@@ -1519,7 +1519,7 @@ TEST(TLSTest, noHandshakeCloseonError) {
     TestCallback receive_cb;
     server.async_read_some(boost::asio::buffer(receive_buf), receive_cb);
     while (!timeout && !receive_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
@@ -1543,7 +1543,7 @@ TEST(TLSTest, noHandshakeCloseonError) {
 
 // Test what happens when the server was not configured.
 TEST(TLSTest, serverNotConfiguredCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -1553,7 +1553,7 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1570,7 +1570,7 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1596,7 +1596,7 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1642,7 +1642,7 @@ TEST(TLSTest, serverNotConfiguredCloseonError) {
 
 // Test what happens when the client was not configured.
 TEST(TLSTest, clientNotConfiguredCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1652,7 +1652,7 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1669,7 +1669,7 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1695,7 +1695,7 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
     TestCallback client_cb(&client.lowest_layer());
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1740,7 +1740,7 @@ TEST(TLSTest, clientNotConfiguredCloseonError) {
 
 // Test what happens when the client is HTTP (vs HTTPS).
 TEST(TLSTest, clientHTTPnoSCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1750,13 +1750,13 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
 
     // Client part.
-    tcp::socket client(service.getInternalIOService());
+    tcp::socket client(service->getInternalIOService());
 
     // Connect to.
     client.open(tcp::v4());
@@ -1765,7 +1765,7 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1795,7 +1795,7 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
     client.async_send(boost::asio::buffer(send_buf), client_cb);
 
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1835,7 +1835,7 @@ TEST(TLSTest, clientHTTPnoSCloseonError) {
 
 // Test what happens when the client uses a certificate from another CA.
 TEST(TLSTest, anotherClientCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1845,7 +1845,7 @@ TEST(TLSTest, anotherClientCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1862,7 +1862,7 @@ TEST(TLSTest, anotherClientCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1888,7 +1888,7 @@ TEST(TLSTest, anotherClientCloseonError) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -1934,7 +1934,7 @@ TEST(TLSTest, anotherClientCloseonError) {
 
 // Test what happens when the client uses a self-signed certificate.
 TEST(TLSTest, selfSignedCloseonError) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -1944,7 +1944,7 @@ TEST(TLSTest, selfSignedCloseonError) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -1961,7 +1961,7 @@ TEST(TLSTest, selfSignedCloseonError) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -1987,7 +1987,7 @@ TEST(TLSTest, selfSignedCloseonError) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2040,7 +2040,7 @@ TEST(TLSTest, selfSignedCloseonError) {
 // Test what happens when the client uses a certificate from another CA
 // but the client certificate request and validation are disabled.
 TEST(TLSTest, anotherClientNoReq) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -2050,7 +2050,7 @@ TEST(TLSTest, anotherClientNoReq) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2067,7 +2067,7 @@ TEST(TLSTest, anotherClientNoReq) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2093,7 +2093,7 @@ TEST(TLSTest, anotherClientNoReq) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2112,7 +2112,7 @@ TEST(TLSTest, anotherClientNoReq) {
 // Test what happens when the server uses a certificate without subject
 // alternative name (but still a version 3 certificate).
 TEST(TLSTest, serverRaw) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -2122,7 +2122,7 @@ TEST(TLSTest, serverRaw) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2139,7 +2139,7 @@ TEST(TLSTest, serverRaw) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2165,7 +2165,7 @@ TEST(TLSTest, serverRaw) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2185,7 +2185,7 @@ TEST(TLSTest, serverRaw) {
 // Test what happens when the client uses a trusted self-signed certificate.
 // Not really a failure case as it works...
 TEST(TLSTest, trustedSelfSigned) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx;
@@ -2195,7 +2195,7 @@ TEST(TLSTest, trustedSelfSigned) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2212,7 +2212,7 @@ TEST(TLSTest, trustedSelfSigned) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2238,7 +2238,7 @@ TEST(TLSTest, trustedSelfSigned) {
     TestCallback client_cb;
     client.async_handshake(roleToImpl(TlsRole::CLIENT), client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2263,7 +2263,7 @@ TEST(TLSTest, trustedSelfSigned) {
 
 // Test what happens when the shutdown receiver is inactive.
 TEST(TLSTest, shutdownInactive) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -2273,7 +2273,7 @@ TEST(TLSTest, shutdownInactive) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2290,7 +2290,7 @@ TEST(TLSTest, shutdownInactive) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2316,7 +2316,7 @@ TEST(TLSTest, shutdownInactive) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2336,7 +2336,7 @@ TEST(TLSTest, shutdownInactive) {
     TestCallback shutdown_cb;
     client.shutdown(shutdown_cb);
     while (!timeout && !shutdown_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
@@ -2361,7 +2361,7 @@ TEST(TLSTest, shutdownInactive) {
 
 // Test what happens when the shutdown receiver is active.
 TEST(TLSTest, shutdownActive) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -2371,7 +2371,7 @@ TEST(TLSTest, shutdownActive) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2388,7 +2388,7 @@ TEST(TLSTest, shutdownActive) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2414,7 +2414,7 @@ TEST(TLSTest, shutdownActive) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2439,7 +2439,7 @@ TEST(TLSTest, shutdownActive) {
     TestCallback shutdown_cb;
     client.shutdown(shutdown_cb);
     while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
@@ -2473,7 +2473,7 @@ TEST(TLSTest, shutdownActive) {
 // Test what happens when the shutdown receiver is inactive on shutdown
 // and immediate close.
 TEST(TLSTest, shutdownCloseInactive) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -2483,7 +2483,7 @@ TEST(TLSTest, shutdownCloseInactive) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2500,7 +2500,7 @@ TEST(TLSTest, shutdownCloseInactive) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2526,7 +2526,7 @@ TEST(TLSTest, shutdownCloseInactive) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2547,9 +2547,9 @@ TEST(TLSTest, shutdownCloseInactive) {
     client.shutdown(shutdown_cb);
 
     // Post a close which should be called after the shutdown.
-    service.post([&client] { client.lowest_layer().close(); });
+    service->post([&client] { client.lowest_layer().close(); });
     while (!timeout && !shutdown_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
@@ -2577,7 +2577,7 @@ TEST(TLSTest, shutdownCloseInactive) {
 // Test what happens when the shutdown receiver is active with an
 // immediate close.
 TEST(TLSTest, shutdownCloseActive) {
-    IOService service;
+    IOServicePtr service(new IOService());
 
     // Server part.
     TlsContextPtr server_ctx(new TlsContext(TlsRole::SERVER));
@@ -2587,7 +2587,7 @@ TEST(TLSTest, shutdownCloseActive) {
     // Accept a client.
     tcp::endpoint server_ep(tcp::endpoint(address::from_string(SERVER_ADDRESS),
                                           SERVER_PORT));
-    tcp::acceptor acceptor(service.getInternalIOService(), server_ep);
+    tcp::acceptor acceptor(service->getInternalIOService(), server_ep);
     acceptor.set_option(tcp::acceptor::reuse_address(true));
     TestCallback accept_cb;
     acceptor.async_accept(server.lowest_layer(), accept_cb);
@@ -2604,7 +2604,7 @@ TEST(TLSTest, shutdownCloseActive) {
 
     // Run accept and connect.
     while (!accept_cb.getCalled() || !connect_cb.getCalled()) {
-        service.runOne();
+        service->runOne();
     }
 
     // Verify the error codes.
@@ -2630,7 +2630,7 @@ TEST(TLSTest, shutdownCloseActive) {
     TestCallback client_cb;
     client.handshake(client_cb);
     while (!timeout && (!server_cb.getCalled() || !client_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer.cancel();
 
@@ -2656,9 +2656,9 @@ TEST(TLSTest, shutdownCloseActive) {
     client.shutdown(shutdown_cb);
 
     // Post a close which should be called after the shutdown.
-    service.post([&client] { client.lowest_layer().close(); });
+    service->post([&client] { client.lowest_layer().close(); });
     while (!timeout && (!shutdown_cb.getCalled() || !receive_cb.getCalled())) {
-        service.runOne();
+        service->runOne();
     }
     timer2.cancel();
 
index cc16d0ae1a8c60c865260f9a30e6ef6801ef7f9a..5ef43c167d4119c2da2a01b46821add25aea58ed 100644 (file)
@@ -158,17 +158,16 @@ private:
 // two bytes of a buffer.
 
 TEST(UDPSocket, processReceivedData) {
-    IOService               service;        // Used to instantiate socket
-    UDPSocket<UDPCallback>  test(service);  // Socket under test
-    uint8_t                 inbuff[32];     // Buffer to check
-    OutputBufferPtr         outbuff(new OutputBuffer(16));
-                                            // Where data is put
-                                            // cppcheck-suppress variableScope
-    size_t                  expected;       // Expected amount of data
-                                            // cppcheck-suppress variableScope
-    size_t                  offset;         // Where to put next data
-                                            // cppcheck-suppress variableScope
-    size_t                  cumulative;     // Cumulative data received
+    IOServicePtr            service(new IOService());      // Used to instantiate socket
+    UDPSocket<UDPCallback>  test(service);                 // Socket under test
+    uint8_t                 inbuff[32];                    // Buffer to check
+    OutputBufferPtr         outbuff(new OutputBuffer(16)); // Where data is put
+                                                           // cppcheck-suppress variableScope
+    size_t                  expected;                      // Expected amount of data
+                                                           // cppcheck-suppress variableScope
+    size_t                  offset;                        // Where to put next data
+                                                           // cppcheck-suppress variableScope
+    size_t                  cumulative;                    // Cumulative data received
 
     // Set some dummy values in the buffer to check
     for (uint8_t i = 0; i < sizeof(inbuff); ++i) {
@@ -206,31 +205,27 @@ TEST(UDPSocket, processReceivedData) {
 // message to a server, receiving an asynchronous message from the server and
 // closing.
 TEST(UDPSocket, SequenceTest) {
-
     // Common objects.
-    IOService   service;                    // Service object for async control
-
+    IOServicePtr service(new IOService());                    // Service object for async control
     // Server
-    IOAddress   server_address(SERVER_ADDRESS); // Address of target server
-    UDPCallback server_cb("Server");        // Server callback
-    UDPEndpoint server_endpoint(            // Endpoint describing server
-        server_address, SERVER_PORT);
-    UDPEndpoint server_remote_endpoint;     // Address where server received message from
+    IOAddress   server_address(SERVER_ADDRESS);               // Address of target server
+    UDPCallback server_cb("Server");                          // Server callback
+    UDPEndpoint server_endpoint(server_address, SERVER_PORT); // Endpoint describing server
+    UDPEndpoint server_remote_endpoint;                       // Address where server received message from
 
     // The client - the UDPSocket being tested
-    UDPSocket<UDPCallback>  client(service);// Socket under test
-    UDPCallback client_cb("Client");        // Async I/O callback function
-    UDPEndpoint client_remote_endpoint;     // Where client receives message from
-    size_t      client_cumulative = 0;      // Cumulative data received
-    size_t      client_offset = 0;          // Offset into buffer where data is put
-    size_t      client_expected = 0;        // Expected amount of data
-    OutputBufferPtr client_buffer(new OutputBuffer(16));
-                                            // Where data is put
+    UDPSocket<UDPCallback>  client(service);                  // Socket under test
+    UDPCallback client_cb("Client");                          // Async I/O callback function
+    UDPEndpoint client_remote_endpoint;                       // Where client receives message from
+    size_t      client_cumulative = 0;                        // Cumulative data received
+    size_t      client_offset = 0;                            // Offset into buffer where data is put
+    size_t      client_expected = 0;                          // Expected amount of data
+    OutputBufferPtr client_buffer(new OutputBuffer(16));      // Where data is put
 
     // The server - with which the client communicates.  For convenience, we
     // use the same io_service, and use the endpoint object created for
     // the client to send to as the endpoint object in the constructor.
-    boost::asio::ip::udp::socket server(service.getInternalIOService(),
+    boost::asio::ip::udp::socket server(service->getInternalIOService(),
         server_endpoint.getASIOEndpoint());
     server.set_option(socket_base::reuse_address(true));
 
@@ -250,15 +245,15 @@ TEST(UDPSocket, SequenceTest) {
     EXPECT_FALSE(server_cb.getCalled());
 
     // Write something to the server using the client - the callback should not
-    // be called until we call the io_service.run() method.
+    // be called until we call the io_service->run() method.
     client_cb.setCalled(false);
     client_cb.setCode(7);  // Arbitrary number
     client.asyncSend(OUTBOUND_DATA, sizeof(OUTBOUND_DATA), &server_endpoint, client_cb);
     EXPECT_FALSE(client_cb.getCalled());
 
     // Execute the two callbacks.
-    service.runOne();
-    service.runOne();
+    service->runOne();
+    service->runOne();
 
     EXPECT_TRUE(client_cb.getCalled());
     EXPECT_EQ(0, client_cb.getCode());
@@ -286,8 +281,8 @@ TEST(UDPSocket, SequenceTest) {
         server_remote_endpoint.getASIOEndpoint(), server_cb);
 
     // Expect two callbacks to run.
-    service.runOne();
-    service.runOne();
+    service->runOne();
+    service->runOne();
 
     EXPECT_TRUE(client_cb.getCalled());
     EXPECT_EQ(0, client_cb.getCode());
index 033c80375a85f78e5241d1ff11760ff8ec2df9a7..b237d0cf13e0455a32c4597c969f68f0dba5c00c 100644 (file)
@@ -33,7 +33,7 @@ public:
     ///
     /// Removes unix socket descriptor before the test.
     UnixDomainSocketTest() :
-        io_service_(),
+        io_service_(new IOService()),
         test_socket_(new test::TestServerUnixSocket(io_service_,
                                                     unixSocketFilePath())),
         response_(),
@@ -105,7 +105,7 @@ public:
     }
 
     /// @brief IO service used by the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Server side unix socket used in these tests.
     test::TestServerUnixSocketPtr test_socket_;
@@ -138,7 +138,7 @@ TEST_F(UnixDomainSocketTest, sendReceive) {
     // Run IO service to generate server's response.
     while ((test_socket_->getResponseNum() < 1) &&
            (!test_socket_->isStopped())) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // Receive response from the socket.
@@ -179,7 +179,7 @@ TEST_F(UnixDomainSocketTest, asyncSendReceive) {
     ));
     // Run IO service until connect handler is invoked.
     while (!connect_handler_invoked && (!test_socket_->isStopped())) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // We are going to asynchronously send the 'foo' over the unix socket.
@@ -202,7 +202,7 @@ TEST_F(UnixDomainSocketTest, asyncSendReceive) {
     // Run IO service to generate server's response.
     while ((test_socket_->getResponseNum() < 1) &&
            (!test_socket_->isStopped())) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // There is no guarantee that all data have been sent so we only check that
@@ -215,7 +215,7 @@ TEST_F(UnixDomainSocketTest, asyncSendReceive) {
     // Run IO service until we get the full response from the server.
     while ((response_.size() < expected_response.size()) &&
            !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // Check that the entire response has been received and is correct.
@@ -259,7 +259,7 @@ TEST_F(UnixDomainSocketTest, asyncClientErrors) {
         EXPECT_TRUE(ec);
     });
     while (!connect_handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // Send
@@ -272,7 +272,7 @@ TEST_F(UnixDomainSocketTest, asyncClientErrors) {
         EXPECT_TRUE(ec);
     });
     while (!send_handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 
     // Receive
@@ -285,7 +285,7 @@ TEST_F(UnixDomainSocketTest, asyncClientErrors) {
         EXPECT_TRUE(ec);
     });
     while (!receive_handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 }
 
index 93d53d96d56f9ae15c612052874beacbfae5bee3..9df24be1b21ba7e560d5f6a94af113778b40a728 100644 (file)
@@ -142,7 +142,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service Reference to the IO service.
-    ConnectionPool(IOService& io_service)
+    ConnectionPool(IOServicePtr& io_service)
         : io_service_(io_service), connections_(), next_socket_(),
           response_num_(0) {
     }
@@ -160,7 +160,7 @@ public:
     /// @return Pointer to the socket.
     UnixSocketPtr getSocket() {
         if (!next_socket_) {
-            next_socket_.reset(new UnixSocket(io_service_.getInternalIOService()));
+            next_socket_.reset(new UnixSocket(io_service_->getInternalIOService()));
         }
         return (next_socket_);
     }
@@ -206,8 +206,8 @@ public:
 
 private:
 
-    /// @brief Reference to the IO service.
-    IOService& io_service_;
+    /// @brief Pointer to the IO service.
+    IOServicePtr io_service_;
 
     /// @brief Container holding established connections.
     std::set<ConnectionPtr> connections_;
@@ -222,15 +222,15 @@ private:
 };
 
 
-TestServerUnixSocket::TestServerUnixSocket(IOService& io_service,
+TestServerUnixSocket::TestServerUnixSocket(const IOServicePtr& io_service,
                                            const std::string& socket_file_path,
                                            const std::string& custom_response)
     : io_service_(io_service),
       server_endpoint_(socket_file_path),
-      server_acceptor_(io_service_.getInternalIOService()),
+      server_acceptor_(io_service_->getInternalIOService()),
       test_timer_(io_service_),
       custom_response_(custom_response),
-      connection_pool_(new ConnectionPool(io_service)),
+      connection_pool_(new ConnectionPool(io_service_)),
       stopped_(false),
       running_(false) {
 }
@@ -274,8 +274,7 @@ TestServerUnixSocket::bindServerSocket(const bool use_thread) {
     // when the thread has already started and the IO service is running. The
     // main thread can move forward when it receives this signal from the handler.
     if (use_thread) {
-        io_service_.post(std::bind(&TestServerUnixSocket::signalRunning,
-                                   this));
+        io_service_->post(std::bind(&TestServerUnixSocket::signalRunning, this));
     }
 }
 
@@ -292,8 +291,7 @@ TestServerUnixSocket::acceptHandler(const boost::system::error_code& ec) {
 void
 TestServerUnixSocket::accept() {
     server_acceptor_.async_accept(*(connection_pool_->getSocket()),
-        std::bind(&TestServerUnixSocket::acceptHandler, this,
-                  ph::_1)); // error
+        std::bind(&TestServerUnixSocket::acceptHandler, this, ph::_1)); // error
 }
 
 void
@@ -316,7 +314,7 @@ TestServerUnixSocket::waitForRunning() {
 void
 TestServerUnixSocket::timeoutHandler() {
     ADD_FAILURE() << "Timeout occurred while running the test!";
-    io_service_.stop();
+    io_service_->stop();
     stopped_ = true;
 }
 
index cf156738c22ada8e59ab0898c5759f7b71448645..2b00aa40f77de7f522a246535d873c050983b6d3 100644 (file)
@@ -53,7 +53,7 @@ public:
     /// @param io_service IO service.
     /// @param socket_file_path Socket file path.
     /// @param custom_response Custom response to be sent to the client.
-    TestServerUnixSocket(IOService& io_service,
+    TestServerUnixSocket(const IOServicePtr& io_service,
                          const std::string& socket_file_path,
                          const std::string& custom_response = "");
 
@@ -123,7 +123,7 @@ private:
     void signalRunning();
 
     /// @brief IO service used by the tests.
-    IOService& io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Server endpoint.
     boost::asio::local::stream_protocol::endpoint server_endpoint_;
index f1cd0c977555e5ac23ad06f9b24c60d5a54da498..0b949223b71c8f3e2bc0de541104dd398831ca06 100644 (file)
@@ -31,7 +31,7 @@ public:
     /// raised.
     /// @param mode selects between a one-shot signal or a signal which repeats
     /// at "milliseconds" interval.
-    TimedSignal(asiolink::IOService& io_service, int signum, int milliseconds,
+    TimedSignal(asiolink::IOServicePtr& io_service, int signum, int milliseconds,
                 const asiolink::IntervalTimer::Mode& mode =
                 asiolink::IntervalTimer::ONE_SHOT)
         : timer_(new asiolink::IntervalTimer(io_service)) {
index c5755592c081f81108251154e65c7b68b0698354..1acac5ce3d17d00622cd1fbbb4097bcff42239dd 100644 (file)
@@ -34,7 +34,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service IO service.
-    explicit TLSAcceptor(IOService& io_service) : TCPAcceptor<C>(io_service) {
+    explicit TLSAcceptor(const IOServicePtr& io_service) : TCPAcceptor<C>(io_service) {
     }
 
     /// @brief Destructor.
index cdd2f78d0c020a140daa07d1487df319a7d50756..179952d98fe3382f27b754cd6618dec3fc258a3e 100644 (file)
@@ -42,7 +42,7 @@ public:
     ///
     /// @param service I/O Service object used to manage the socket.
     /// @param context Pointer to TLS context.
-    TLSSocket(IOService& service, TlsContextPtr context);
+    TLSSocket(const IOServicePtr& service, TlsContextPtr context);
 
     /// @brief Destructor.
     virtual ~TLSSocket() { }
@@ -224,6 +224,9 @@ public:
     }
 
 private:
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+
     /// Two variables to hold the stream - a stream and a pointer to it.  This
     /// handles the case where a stream is passed to the TLSSocket on
     /// construction, or where it is asked to manage its own stream.
@@ -266,10 +269,10 @@ TLSSocket<C>::TLSSocket(TlsStream<C>& stream) :
 // Constructor - create socket on the fly.
 
 template <typename C>
-TLSSocket<C>::TLSSocket(IOService& service, TlsContextPtr context) :
-    stream_ptr_(new TlsStream<C>(service, context)),
-    stream_(*stream_ptr_), socket_(stream_.lowest_layer()), send_buffer_()
-{
+TLSSocket<C>::TLSSocket(const IOServicePtr& io_service, TlsContextPtr context)
+    : io_service_(io_service),
+      stream_ptr_(new TlsStream<C>(io_service, context)),
+      stream_(*stream_ptr_), socket_(stream_.lowest_layer()), send_buffer_() {
 }
 
 // Open the socket.
index 095ede45763fd79cb9cbeff5007381f2c3f7b6c5..68adb351d8d8bb607616b1d943890a1ca11373be 100644 (file)
@@ -56,7 +56,7 @@ public:
     /// socket.  In this case, the open() and close() methods are used.
     ///
     /// \param service I/O Service object used to manage the socket.
-    UDPSocket(IOService& service);
+    UDPSocket(const IOServicePtr& service);
 
     /// \brief Destructor
     virtual ~UDPSocket();
@@ -147,6 +147,9 @@ public:
 
 
 private:
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+
     // Two variables to hold the socket - a socket and a pointer to it.  This
     // handles the case where a socket is passed to the UDPSocket on
     // construction, or where it is asked to manage its own socket.
@@ -172,8 +175,8 @@ UDPSocket<C>::UDPSocket(boost::asio::ip::udp::socket& socket) :
 // Constructor - create socket on the fly
 
 template <typename C>
-UDPSocket<C>::UDPSocket(IOService& service) :
-    socket_ptr_(new boost::asio::ip::udp::socket(service.getInternalIOService())),
+UDPSocket<C>::UDPSocket(const IOServicePtr& io_service) : io_service_(io_service),
+    socket_ptr_(new boost::asio::ip::udp::socket(io_service_->getInternalIOService())),
     socket_(*socket_ptr_), isopen_(false)
 {
 }
index e5c3dd27ad29c352e53f52644181e98cbf73ad83..12efab3917f470a8f44eb46c3cc6af1ccd028f27 100644 (file)
@@ -25,8 +25,8 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service IO service to be used by the socket class.
-    UnixDomainSocketImpl(IOService& io_service)
-        : socket_(io_service.getInternalIOService()) {
+    UnixDomainSocketImpl(const IOServicePtr& io_service)
+        : io_service_(io_service), socket_(io_service_->getInternalIOService()) {
     }
 
     /// @brief Destructor.
@@ -159,6 +159,9 @@ public:
     /// @brief Closes the socket.
     void close();
 
+    /// @brief The IO service used to handle events.
+    IOServicePtr io_service_;
+
     /// @brief Instance of the boost asio unix domain socket.
     stream_protocol::socket socket_;
 };
@@ -280,7 +283,7 @@ UnixDomainSocketImpl::close() {
     }
 }
 
-UnixDomainSocket::UnixDomainSocket(IOService& io_service)
+UnixDomainSocket::UnixDomainSocket(const IOServicePtr& io_service)
     : impl_(new UnixDomainSocketImpl(io_service)) {
 }
 
index cd02f41e5694e019e7d10c9459f0d5d9fc8de7bd..b0f4358bffc538cc131385bdacd27ed3b10789b6 100644 (file)
@@ -41,7 +41,7 @@ public:
     ///
     /// @param io_service Reference to IOService to be used by this
     /// class.
-    explicit UnixDomainSocket(IOService& io_service);
+    explicit UnixDomainSocket(const IOServicePtr& io_service);
 
     /// @brief Returns native socket representation.
     virtual int getNative() const;
index 8aa11cadcaa33578dd75425510a91dc130e29d36..aa3d04ea7180327832b2f7920b0ea8fa5a840dae 100644 (file)
@@ -32,7 +32,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service Reference to the IO service.
-    explicit UnixDomainSocketAcceptor(IOService& io_service)
+    explicit UnixDomainSocketAcceptor(const IOServicePtr& io_service)
         : IOAcceptor<boost::asio::local::stream_protocol,
                      std::function<void(const boost::system::error_code&)> >(io_service) {
     }
index 6217c1aae131234d53208a3be709e4969a064935..6f53eca261eea009c5d85dd75507b9a633b4d81e 100644 (file)
@@ -27,7 +27,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service Reference to the IO service.
-    explicit ClientConnectionImpl(IOService& io_service);
+    explicit ClientConnectionImpl(const IOServicePtr& io_service);
 
     /// @brief This method schedules timer or reschedules existing timer.
     ///
@@ -115,7 +115,7 @@ private:
     long timeout_;
 };
 
-ClientConnectionImpl::ClientConnectionImpl(IOService& io_service)
+ClientConnectionImpl::ClientConnectionImpl(const IOServicePtr& io_service)
     : socket_(io_service), feed_(), current_command_(), timer_(io_service),
       timeout_(0) {
 }
@@ -268,7 +268,7 @@ ClientConnectionImpl::timeoutCallback(ClientConnection::Handler handler) {
     terminate(boost::asio::error::timed_out, handler);
 }
 
-ClientConnection::ClientConnection(asiolink::IOService& io_service)
+ClientConnection::ClientConnection(const IOServicePtr& io_service)
     : impl_(new ClientConnectionImpl(io_service)) {
 }
 
@@ -280,6 +280,5 @@ ClientConnection::start(const ClientConnection::SocketPath& socket_path,
     impl_->start(socket_path, command, handler, timeout);
 }
 
-
 } // end of namespace config
 } // end of namespace isc
index b88854bcd875419ec23fead8c0adcc1d5fb15c7b..0cd25c66b54fc4e6fab94ef4d4b45755650e2744 100644 (file)
@@ -108,7 +108,7 @@ public:
     /// @brief Constructor.
     ///
     /// @param io_service Reference to the IO service.
-    explicit ClientConnection(asiolink::IOService& io_service);
+    explicit ClientConnection(const asiolink::IOServicePtr& io_service);
 
     /// @brief Starts asynchronous transaction with a remote endpoint.
     ///
index aa917c78246112a8d1957a92fcac70aecdcd2794..e02f65eec0c7e788698672fd053776e8d5aa7d72 100644 (file)
@@ -62,7 +62,7 @@ CmdHttpListener::start() {
 
         // Create the HTTP listener. It will open up a TCP socket and be
         // prepared to accept incoming connections.
-        http_listener_.reset(new HttpListener(*thread_io_service_, address_,
+        http_listener_.reset(new HttpListener(thread_io_service_, address_,
                                               port_, tls_context_, rcf,
                                               HttpListener::RequestTimeout(TIMEOUT_AGENT_RECEIVE_COMMAND),
                                               HttpListener::IdleTimeout(TIMEOUT_AGENT_IDLE_CONNECTION_TIMEOUT)));
index 8dcb84072aed6ffff1d8b9a8b965c321d30e4732..cf21a697abc96742bd90296a0fb01f9feca45006 100644 (file)
@@ -67,7 +67,7 @@ public:
                const boost::shared_ptr<UnixDomainSocket>& socket,
                ConnectionPool& connection_pool,
                const long timeout)
-        : socket_(socket), timeout_timer_(*io_service), timeout_(timeout),
+        : socket_(socket), timeout_timer_(io_service), timeout_(timeout),
           buf_(), response_(), connection_pool_(connection_pool), feed_(),
           response_in_progress_(false), watch_socket_(new util::WatchSocket()) {
 
@@ -181,7 +181,6 @@ public:
     void receiveHandler(const boost::system::error_code& ec,
                         size_t bytes_transferred);
 
-
     /// @brief Handler invoked when the data is sent over the control socket.
     ///
     /// If there are still data to be sent, another asynchronous send is
@@ -463,7 +462,6 @@ Connection::timeoutHandler() {
     doSend();
 }
 
-
 }
 
 namespace isc {
@@ -575,7 +573,7 @@ CommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_info)
 
     try {
         // Start asynchronous acceptor service.
-        acceptor_.reset(new UnixDomainSocketAcceptor(*io_service_));
+        acceptor_.reset(new UnixDomainSocketAcceptor(io_service_));
         UnixDomainSocketEndpoint endpoint(socket_name_);
         acceptor_->open(endpoint);
         acceptor_->bind(endpoint);
@@ -593,7 +591,7 @@ CommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_info)
 void
 CommandMgrImpl::doAccept() {
     // Create a socket into which the acceptor will accept new connection.
-    socket_.reset(new UnixDomainSocket(*io_service_));
+    socket_.reset(new UnixDomainSocket(io_service_));
     acceptor_->asyncAccept(*socket_, [this](const boost::system::error_code& ec) {
         if (!ec) {
             // New connection is arriving. Start asynchronous transmission.
@@ -644,7 +642,6 @@ CommandMgr::getControlSocketFD() {
     return (impl_->acceptor_ ? impl_->acceptor_->getNative() : -1);
 }
 
-
 CommandMgr&
 CommandMgr::instance() {
     static CommandMgr cmd_mgr;
@@ -661,6 +658,5 @@ CommandMgr::setConnectionTimeout(const long timeout) {
     impl_->timeout_ = timeout;
 }
 
-
-}; // end of isc::config
-}; // end of isc
+} // end of isc::config
+} // end of isc
index 9e57575fb68553978f90288f5e7dbd2970d2aaa6..38597ce810d1c45e0848f8d8b2c0943485161a49 100644 (file)
@@ -33,7 +33,7 @@ public:
     ///
     /// Removes unix socket descriptor before the test.
     ClientConnectionTest() :
-        io_service_(),
+        io_service_(new IOService()),
         test_socket_(new test::TestServerUnixSocket(io_service_,
                                                     unixSocketFilePath())) {
         removeUnixSocketFile();
@@ -76,7 +76,7 @@ public:
     }
 
     /// @brief IO service used by the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Server side unix socket used in these tests.
     test::TestServerUnixSocketPtr test_socket_;
@@ -116,7 +116,7 @@ TEST_F(ClientConnectionTest, success) {
     });
     // Run the connection.
     while (!handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 }
 
@@ -153,7 +153,7 @@ TEST_F(ClientConnectionTest, timeout) {
     }, ClientConnection::Timeout(1000));
 
     while (!handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 }
 
@@ -176,7 +176,7 @@ TEST_F(ClientConnectionTest, connectionError) {
     });
 
     while (!handler_invoked && !test_socket_->isStopped()) {
-        io_service_.runOne();
+        io_service_->runOne();
     }
 }
 
index 0093980411f535dfc03b0356cff3e1522af107cb..fbb5c8ac790f1dec15c87268e0d20ea2c2a53cc2 100644 (file)
@@ -54,7 +54,7 @@ public:
     /// Starts test timer which detects timeouts, deregisters all commands
     /// from CommandMgr, and enables multi-threading mode.
     CmdHttpListenerTest()
-        : listener_(), io_service_(), test_timer_(io_service_),
+        : listener_(), io_service_(new IOService()), test_timer_(io_service_),
           run_io_service_timer_(io_service_), clients_(), num_threads_(),
           num_clients_(), num_in_progress_(0), num_finished_(0), chunk_size_(0),
           pause_cnt_(0) {
@@ -171,7 +171,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs IO service with optional timeout.
@@ -192,10 +192,10 @@ public:
         size_t num_done = 0;
         while (num_done != request_limit) {
             // Always call restart() before we call run();
-            io_service_.restart();
+            io_service_->restart();
 
             // Run until a client stops the service.
-            io_service_.run();
+            io_service_->run();
 
             // If all the clients are done receiving, the test is done.
             num_done = 0;
@@ -687,7 +687,7 @@ public:
     CmdHttpListenerPtr listener_;
 
     /// @brief IO service used in drive the test and test clients.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Asynchronous timer service to detect timeouts.
     IntervalTimer test_timer_;
index 57982076705f00d2922d5dfade7348d495d6e94c..4467577dc22b135ff83aa36d5434e05224665fb7 100644 (file)
@@ -100,7 +100,7 @@ public:
     /// @param tsig_key A pointer to an @c D2TsigKeyPtr object that will
     /// (if not null) be used to sign the DNS Update message and verify the
     /// response.
-    void doUpdate(asiolink::IOService& io_service,
+    void doUpdate(const asiolink::IOServicePtr& io_service,
                   const asiolink::IOAddress& ns_addr,
                   const uint16_t ns_port,
                   D2UpdateMessage& update,
@@ -222,7 +222,7 @@ DNSClientImpl::getStatus(const asiodns::IOFetch::Result result) {
 }
 
 void
-DNSClientImpl::doUpdate(asiolink::IOService& io_service,
+DNSClientImpl::doUpdate(const asiolink::IOServicePtr& io_service,
                         const IOAddress& ns_addr,
                         const uint16_t ns_port,
                         D2UpdateMessage& update,
@@ -275,7 +275,7 @@ DNSClientImpl::doUpdate(asiolink::IOService& io_service,
 
     // Post the task to the task queue in the IO service. Caller will actually
     // run these tasks by executing IOService::run.
-    io_service.post(io_fetch);
+    io_service->post(io_fetch);
 
     // Update sent statistics.
     incrStats("update-sent");
@@ -311,7 +311,7 @@ DNSClient::getMaxTimeout() {
 }
 
 void
-DNSClient::doUpdate(asiolink::IOService& io_service,
+DNSClient::doUpdate(const asiolink::IOServicePtr& io_service,
                     const IOAddress& ns_addr,
                     const uint16_t ns_port,
                     D2UpdateMessage& update,
index c63a7a0c0a07000cd940051f357faf7e904647cd..63a2c5c16ac8492f70ec6fe834d2c3a63f6e5eec 100644 (file)
@@ -139,7 +139,7 @@ public:
     /// @param tsig_key A pointer to an @c D2TsigKeyPtr object that will
     /// (if not null) be used to sign the DNS Update message and verify the
     /// response.
-    void doUpdate(asiolink::IOService& io_service,
+    void doUpdate(const asiolink::IOServicePtr& io_service,
                   const asiolink::IOAddress& ns_addr,
                   const uint16_t ns_port,
                   D2UpdateMessage& update,
index e9534c256c85647bc063c8eb5795742439c0a63d..e9adce5432fb27179b3d0a3fc8439cef2f9e5db8 100644 (file)
@@ -197,7 +197,7 @@ NameChangeTransaction::sendUpdate(const std::string& comment) {
         // for the current server.  If not we would need to add that.
 
         D2ParamsPtr d2_params = cfg_mgr_->getD2Params();
-        dns_client_->doUpdate(*io_service_, current_server_->getIpAddress(),
+        dns_client_->doUpdate(io_service_, current_server_->getIpAddress(),
                               current_server_->getPort(), *dns_update_request_,
                               d2_params->getDnsServerTimeout(), tsig_key_);
         // Message is on its way, so the next event should be NOP_EVT.
index 76a02a037964bebaf2e51b7f6f4fb3c9d478bdfe..9ffe0963e1d7c620e36b36bad4e3ff2912b4a148 100644 (file)
@@ -60,7 +60,7 @@ class DNSClientTest : public ::testing::Test, DNSClient::Callback,
                       public D2StatTest {
 public:
     /// @brief The IOService which handles IO operations.
-    IOService service_;
+    IOServicePtr service_;
 
     /// @brief The UDP socket.
     std::unique_ptr<udp::socket> socket_;
@@ -107,7 +107,7 @@ public:
     /// waiting for a response. Some of the tests are checking DNSClient behavior
     /// in case when response from the server is not received. Tests output would
     /// become messy if such errors were logged.
-    DNSClientTest() : service_(), socket_(), endpoint_(),
+    DNSClientTest() : service_(new IOService()), socket_(), endpoint_(),
                       status_(DNSClient::SUCCESS), corrupt_response_(false),
                       expect_response_(true), test_timer_(service_),
                       received_(0), expected_(0), go_on_(false) {
@@ -136,7 +136,7 @@ public:
     virtual void operator()(DNSClient::Status status) {
         status_ = status;
         if (!expected_ || (expected_ == ++received_)) {
-            service_.stop();
+            service_->stop();
         }
 
         if (expect_response_) {
@@ -168,7 +168,7 @@ public:
     ///
     /// This callback stops all running (hanging) tasks on IO service.
     void testTimeoutHandler() {
-        service_.stop();
+        service_->stop();
         FAIL() << "Test timeout hit.";
     }
 
@@ -367,7 +367,7 @@ public:
 
         // This starts the execution of tasks posted to IOService. run() blocks
         // until stop() is called in the completion callback function.
-        service_.run();
+        service_->run();
 
     }
 
@@ -392,7 +392,7 @@ public:
         // responses. The reuse address option is set so as both sockets can
         // use the same address. This new socket is bound to the test address
         // and port, where requests will be sent.
-        socket_.reset(new udp::socket(service_.getInternalIOService(),
+        socket_.reset(new udp::socket(service_->getInternalIOService(),
                                       boost::asio::ip::udp::v4()));
         socket_->set_option(socket_base::reuse_address(true));
         socket_->bind(udp::endpoint(address::from_string(TEST_ADDRESS),
@@ -437,14 +437,14 @@ public:
 
         // Kick of the message exchange by actually running the scheduled
         // "send" and "receive" operations.
-        service_.run();
+        service_->run();
 
         socket_->close();
 
         // 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_.restart();
+        service_->restart();
     }
 
     /// @brief Performs a single request-response exchange with or without TSIG.
@@ -465,7 +465,7 @@ public:
         ASSERT_NO_THROW(message.setZone(Name("example.com"), RRClass::IN()));
 
         // Setup our "loopback" server.
-        udp::socket udp_socket(service_.getInternalIOService(), boost::asio::ip::udp::v4());
+        udp::socket udp_socket(service_->getInternalIOService(), boost::asio::ip::udp::v4());
         udp_socket.set_option(socket_base::reuse_address(true));
         udp_socket.bind(udp::endpoint(address::from_string(TEST_ADDRESS),
                                       TEST_PORT));
@@ -489,14 +489,14 @@ public:
 
         // Kick of the message exchange by actually running the scheduled
         // "send" and "receive" operations.
-        service_.run();
+        service_->run();
 
         udp_socket.close();
 
         // 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_.restart();
+        service_->restart();
     }
 };
 
index 89a23b78065c2f6d1bf0de8009953e212f1ef2c5..e1df8e27e6b23c4243ebbb6310c0363eaa2667d0 100644 (file)
@@ -1000,7 +1000,7 @@ TEST_F(NameChangeTransactionTest, sendUpdateCorruptResponse) {
     ASSERT_TRUE(name_change->selectFwdServer());
 
     // Create a server and start it listening.
-    FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+    FauxServer server(io_service_, *(name_change->getCurrentServer()));
     server.receive(FauxServer::CORRUPT_RESP);
 
     // Build a valid request, call sendUpdate and process the response.
@@ -1020,7 +1020,7 @@ TEST_F(NameChangeTransactionTest, sendUpdate) {
     ASSERT_TRUE(name_change->selectFwdServer());
 
     // Create a server and start it listening.
-    FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+    FauxServer server(io_service_, *(name_change->getCurrentServer()));
     server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Build a valid request, call sendUpdate and process the response.
@@ -1049,7 +1049,7 @@ TEST_F(NameChangeTransactionTest, tsigUnsignedResponse) {
     ASSERT_TRUE(name_change->selectFwdServer());
 
     // Create a server and start it listening.
-    FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+    FauxServer server(io_service_, *(name_change->getCurrentServer()));
     server.receive (FauxServer::USE_RCODE, dns::Rcode::NOERROR());
 
     // Do the update.
@@ -1080,7 +1080,7 @@ TEST_F(NameChangeTransactionTest, tsigInvalidResponse) {
 
     // Create a server, tell it to sign responses with a "random" key,
     // then start it listening.
-    FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+    FauxServer server(io_service_, *(name_change->getCurrentServer()));
     server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
 
     // Do the update.
@@ -1113,7 +1113,7 @@ TEST_F(NameChangeTransactionTest, tsigUnexpectedSignedResponse) {
 
     // Create a server, tell it to sign responses with a "random" key,
     // then start it listening.
-    FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+    FauxServer server(io_service_, *(name_change->getCurrentServer()));
     server.receive (FauxServer::INVALID_TSIG, dns::Rcode::NOERROR());
 
     // Perform an update without TSIG.
@@ -1156,7 +1156,7 @@ TEST_F(NameChangeTransactionTest, tsigAllValid) {
         ASSERT_TRUE(name_change->selectFwdServer());
 
         // Create a server, set its TSIG key, and then start it listening.
-        FauxServer server(*io_service_, *(name_change->getCurrentServer()));
+        FauxServer server(io_service_, *(name_change->getCurrentServer()));
         // Since we create a new server instance each time we need to tell
         // it not reschedule receives automatically.
         server.perpetual_receive_ = false;
index 6791eb96391f4537de0897aa117fd2a9ffdd9695..56c3988e3b30745df5790edc4773f1e2d3175038 100644 (file)
@@ -47,7 +47,6 @@ const char* valid_d2_config = "{ "
                         "    \"port\": 100 } ] } "
                         "] } }";
 
-
 const char* TEST_DNS_SERVER_IP = "127.0.0.1";
 size_t TEST_DNS_SERVER_PORT = 5301;
 
@@ -56,33 +55,32 @@ const bool NO_RDATA = false;
 
 //*************************** FauxServer class ***********************
 
-FauxServer::FauxServer(asiolink::IOService& io_service,
+FauxServer::FauxServer(asiolink::IOServicePtr& io_service,
                        asiolink::IOAddress& address, size_t port)
-    :io_service_(io_service), address_(address), port_(port),
-     server_socket_(), receive_pending_(false), perpetual_receive_(true),
-     tsig_key_() {
+    : io_service_(io_service), address_(address), port_(port),
+      server_socket_(), receive_pending_(false), perpetual_receive_(true),
+      tsig_key_() {
 
-    server_socket_.reset(new boost::asio::ip::udp::socket(io_service_.getInternalIOService(),
-                                                   boost::asio::ip::udp::v4()));
+    server_socket_.reset(new boost::asio::ip::udp::socket(io_service_->getInternalIOService(),
+                                                          boost::asio::ip::udp::v4()));
     server_socket_->set_option(boost::asio::socket_base::reuse_address(true));
 
     isc::asiolink::UDPEndpoint endpoint(address_, port_);
     server_socket_->bind(endpoint.getASIOEndpoint());
 }
 
-FauxServer::FauxServer(asiolink::IOService& io_service,
+FauxServer::FauxServer(asiolink::IOServicePtr& io_service,
                        DnsServerInfo& server)
-    :io_service_(io_service), address_(server.getIpAddress()),
-     port_(server.getPort()), server_socket_(), receive_pending_(false),
-     perpetual_receive_(true), tsig_key_() {
-    server_socket_.reset(new boost::asio::ip::udp::socket(io_service_.getInternalIOService(),
-                                                   boost::asio::ip::udp::v4()));
+    : io_service_(io_service), address_(server.getIpAddress()),
+      port_(server.getPort()), server_socket_(), receive_pending_(false),
+      perpetual_receive_(true), tsig_key_() {
+    server_socket_.reset(new boost::asio::ip::udp::socket(io_service_->getInternalIOService(),
+                                                          boost::asio::ip::udp::v4()));
     server_socket_->set_option(boost::asio::socket_base::reuse_address(true));
     isc::asiolink::UDPEndpoint endpoint(address_, port_);
     server_socket_->bind(endpoint.getASIOEndpoint());
 }
 
-
 FauxServer::~FauxServer() {
 }
 
@@ -210,13 +208,11 @@ FauxServer::requestHandler(const boost::system::error_code& error,
     }
 }
 
-
-
 //********************** TimedIO class ***********************
 
 TimedIO::TimedIO()
-    : io_service_(new isc::asiolink::IOService()),
-     timer_(*io_service_), run_time_(0) {
+    : io_service_(new isc::asiolink::IOService()), timer_(io_service_),
+      run_time_(0) {
 }
 
 TimedIO::~TimedIO() {
@@ -371,7 +367,6 @@ TransactionTest::setupForIPv6Transaction(dhcp_ddns::NameChangeType chg_type,
     setupForIPv6Transaction(chg_type, change_mask, makeTSIGKeyInfo(key_name));
 }
 
-
 //********************** Functions ****************************
 
 void
index dac4abe84405152ddbef6c8167fb482923e09cb5..cd6152cd82dfa8f2420bad04e0e60422c7ad858d 100644 (file)
@@ -42,8 +42,8 @@ public:
         INVALID_TSIG  // Generate a response with the wrong TSIG key
     };
 
-    /// @brief Reference to IOService to use for IO processing.
-    asiolink::IOService& io_service_;
+    /// @brief The IO service used to handle events.
+    asiolink::IOServicePtr io_service_;
 
     /// @brief IP address at which to listen for requests.
     const asiolink::IOAddress& address_;
@@ -77,7 +77,7 @@ public:
     /// @param io_service IOService to be used for socket IO.
     /// @param address  IP address at which the server should listen.
     /// @param port Port number at which the server should listen.
-    FauxServer(asiolink::IOService& io_service, asiolink::IOAddress& address,
+    FauxServer(asiolink::IOServicePtr& io_service, asiolink::IOAddress& address,
                size_t port);
 
     /// @brief Constructor
@@ -85,7 +85,7 @@ public:
     /// @param io_service IOService to be used for socket IO.
     /// @param server DnsServerInfo of server the DNS server. This supplies the
     /// server's ip address and port.
-    FauxServer(asiolink::IOService& io_service, DnsServerInfo& server);
+    FauxServer(asiolink::IOServicePtr& io_service, DnsServerInfo& server);
 
     /// @brief Destructor
     virtual ~FauxServer();
index 8e9e9cf1151d375563108291bd26b0281f2258fa..1179c74adb2a5ca7e48a924391aaf7d88fb0813d 100644 (file)
@@ -58,7 +58,7 @@ NameChangeListener::NameChangeListener(RequestReceiveHandler&
 
 
 void
-NameChangeListener::startListening(isc::asiolink::IOService& io_service) {
+NameChangeListener::startListening(const isc::asiolink::IOServicePtr& io_service) {
     if (amListening()) {
         // This amounts to a programmatic error.
         isc_throw(NcrListenerError, "NameChangeListener is already listening");
@@ -160,14 +160,14 @@ NameChangeListener::invokeRecvHandler(const Result result,
 NameChangeSender::NameChangeSender(RequestSendHandler& send_handler,
                                    size_t send_queue_max)
     : sending_(false), send_handler_(send_handler),
-      send_queue_max_(send_queue_max), io_service_(NULL), mutex_(new mutex) {
+      send_queue_max_(send_queue_max), mutex_(new mutex) {
 
     // Queue size must be big enough to hold at least 1 entry.
     setQueueMaxSize(send_queue_max);
 }
 
 void
-NameChangeSender::startSending(isc::asiolink::IOService& io_service) {
+NameChangeSender::startSending(const isc::asiolink::IOServicePtr& io_service) {
     if (amSending()) {
         // This amounts to a programmatic error.
         isc_throw(NcrSenderError, "NameChangeSender is already sending");
@@ -188,12 +188,12 @@ NameChangeSender::startSending(isc::asiolink::IOService& io_service) {
 }
 
 void
-NameChangeSender::startSendingInternal(isc::asiolink::IOService& io_service) {
+NameChangeSender::startSendingInternal(const isc::asiolink::IOServicePtr& io_service) {
     // Clear send marker.
     ncr_to_send_.reset();
 
     // Remember io service we're given.
-    io_service_ = &io_service;
+    io_service_ = io_service;
     open(io_service);
 
     // Set our status to sending.
@@ -211,7 +211,7 @@ NameChangeSender::stopSending() {
     setSending(false);
 
     // If there is an outstanding IO to complete, attempt to process it.
-    if (ioReady() && io_service_ != NULL) {
+    if (ioReady() && io_service_) {
         try {
             runReadyIO();
         } catch (const std::exception& ex) {
@@ -232,7 +232,7 @@ NameChangeSender::stopSending() {
                   DHCP_DDNS_NCR_SEND_CLOSE_ERROR).arg(ex.what());
     }
 
-    io_service_ = NULL;
+    io_service_.reset();
 }
 
 void
index 664057d961914dc765557c6b5609779496235e75..54633df6250066f22e219d06254e7d6501857f16 100644 (file)
@@ -110,7 +110,6 @@ public:
         isc::Exception(file, line, what) { };
 };
 
-
 /// @brief Abstract interface for receiving NameChangeRequests.
 ///
 /// NameChangeListener provides the means to:
@@ -222,7 +221,7 @@ public:
     ///
     /// @throw NcrListenError if the listener is already "listening" or
     /// in the event the open or doReceive methods fail.
-    void startListening(isc::asiolink::IOService& io_service);
+    void startListening(const isc::asiolink::IOServicePtr& io_service);
 
     /// @brief Closes the IO source and stops listen logic.
     ///
@@ -231,6 +230,7 @@ public:
     void stopListening();
 
 protected:
+
     /// @brief Initiates an asynchronous receive
     ///
     /// Sets context information to indicate that IO is in progress and invokes
@@ -278,7 +278,7 @@ protected:
     ///
     /// @throw If the implementation encounters an error it MUST
     /// throw it as an isc::Exception or derivative.
-    virtual void open(isc::asiolink::IOService& io_service) = 0;
+    virtual void open(const isc::asiolink::IOServicePtr& io_service) = 0;
 
     /// @brief Abstract method which closes the IO source.
     ///
@@ -352,7 +352,6 @@ private:
 /// @brief Defines a smart pointer to an instance of a listener.
 typedef boost::shared_ptr<NameChangeListener> NameChangeListenerPtr;
 
-
 /// @brief Thrown when a NameChangeSender encounters an error.
 class NcrSenderError : public isc::Exception {
 public:
@@ -381,7 +380,6 @@ public:
         isc::Exception(file, line, what) { };
 };
 
-
 /// @brief Abstract interface for sending NameChangeRequests.
 ///
 /// NameChangeSender provides the means to:
@@ -529,7 +527,7 @@ public:
     ///
     /// @throw NcrSenderError if the sender is already "sending" or
     /// NcrSenderOpenError if the open fails.
-    void startSending(isc::asiolink::IOService & io_service);
+    void startSending(const isc::asiolink::IOServicePtr& io_service);
 
     /// @brief Closes the IO sink and stops send logic.
     ///
@@ -588,7 +586,7 @@ private:
     /// @brief Prepares the IO for transmission in a thread safe context.
     ///
     /// @param io_service is the IOService that will handle IO event processing.
-    void startSendingInternal(isc::asiolink::IOService & io_service);
+    void startSendingInternal(const isc::asiolink::IOServicePtr & io_service);
 
     /// @brief Queues the given request to be sent in a thread safe context.
     ///
@@ -677,7 +675,7 @@ protected:
     ///
     /// @throw If the implementation encounters an error it MUST
     /// throw it as an isc::Exception or derivative.
-    virtual void open(isc::asiolink::IOService& io_service) = 0;
+    virtual void open(const isc::asiolink::IOServicePtr& io_service) = 0;
 
     /// @brief Abstract method which closes the IO sink.
     ///
@@ -819,6 +817,16 @@ private:
         sending_ = value;
     }
 
+protected:
+
+    /// @brief Pointer to the IOService currently being used by the sender.
+    /// @note We need to remember the io_service but we receive it by
+    /// reference.  Use a raw pointer to store it.  This value should never be
+    /// exposed and is only valid while in send mode.
+    asiolink::IOServicePtr io_service_;
+
+private:
+
     /// @brief Boolean indicator which tracks sending status.
     bool sending_;
 
@@ -834,12 +842,6 @@ private:
     /// @brief Pointer to the request which is in the process of being sent.
     NameChangeRequestPtr ncr_to_send_;
 
-    /// @brief Pointer to the IOService currently being used by the sender.
-    /// @note We need to remember the io_service but we receive it by
-    /// reference.  Use a raw pointer to store it.  This value should never be
-    /// exposed and is only valid while in send mode.
-    asiolink::IOService* io_service_;
-
     /// @brief The mutex used to protect internal state.
     const boost::scoped_ptr<std::mutex> mutex_;
 };
index c46307e6570b8f04f06e4dd2333af33048f7d255..f32404cb54b7faf404b46054ebe18cb535d868f9 100644 (file)
@@ -86,14 +86,16 @@ NameChangeUDPListener::~NameChangeUDPListener() {
 }
 
 void
-NameChangeUDPListener::open(isc::asiolink::IOService& io_service) {
+NameChangeUDPListener::open(const isc::asiolink::IOServicePtr& io_service) {
     // create our endpoint and bind the low level socket to it.
     isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
 
+    io_service_ = io_service;
+
     // Create the low level socket.
     try {
         asio_socket_.reset(new boost::asio::ip::udp::
-                           socket(io_service.getInternalIOService(),
+                           socket(io_service_->getInternalIOService(),
                                   (ip_address_.isV4() ? boost::asio::ip::udp::v4() :
                                    boost::asio::ip::udp::v6())));
 
@@ -106,6 +108,7 @@ NameChangeUDPListener::open(isc::asiolink::IOService& io_service) {
         asio_socket_->bind(endpoint.getASIOEndpoint());
     } catch (const boost::system::system_error& ex) {
         asio_socket_.reset();
+        io_service_.reset();
         isc_throw (NcrUDPError, ex.code().message());
     }
 
@@ -147,6 +150,7 @@ NameChangeUDPListener::close() {
     }
 
     socket_.reset();
+    io_service_.reset();
 }
 
 void
@@ -226,14 +230,16 @@ NameChangeUDPSender::~NameChangeUDPSender() {
 }
 
 void
-NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
+NameChangeUDPSender::open(const isc::asiolink::IOServicePtr& io_service) {
     // create our endpoint and bind the low level socket to it.
     isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
 
+    io_service_ = io_service;
+
     // Create the low level socket.
     try {
         asio_socket_.reset(new boost::asio::ip::udp::
-                           socket(io_service.getInternalIOService(),
+                           socket(io_service_->getInternalIOService(),
                                   (ip_address_.isV4() ? boost::asio::ip::udp::v4() :
                                    boost::asio::ip::udp::v6())));
 
@@ -245,6 +251,8 @@ NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
         // Bind the low level socket to our endpoint.
         asio_socket_->bind(endpoint.getASIOEndpoint());
     } catch (const boost::system::system_error& ex) {
+        asio_socket_.reset();
+        io_service_.reset();
         isc_throw (NcrUDPError, ex.code().message());
     }
 
@@ -288,6 +296,7 @@ NameChangeUDPSender::close() {
 
     closeWatchSocket();
     watch_socket_.reset();
+    io_service_.reset();
 }
 
 void
index 01284aff7e256bab3da96628081fc2f62c368bb1..2b134238bac584069b77699813c49d6e9de0ea3f 100644 (file)
 
 #include <boost/shared_array.hpp>
 
-
 /// responsibility of the completion handler to perform the steps necessary
 /// to interpret the raw data provided by the service outcome.   The
 /// UDPCallback operator implementation is mostly a pass through.
@@ -351,7 +350,7 @@ public:
     /// @param io_service the IOService which will monitor the socket.
     ///
     /// @throw NcrUDPError if the open fails.
-    virtual void open(isc::asiolink::IOService& io_service);
+    virtual void open(const isc::asiolink::IOServicePtr& io_service);
 
     /// @brief Closes the UDPSocket.
     ///
@@ -397,7 +396,12 @@ public:
     /// the socket receive completion.
     void receiveCompletionHandler(const bool successful,
                                   const UDPCallback* recv_callback);
+
 private:
+
+    /// @brief The IO service used to handle events.
+    isc::asiolink::IOServicePtr io_service_;
+
     /// @brief IP address on which to listen for requests.
     isc::asiolink::IOAddress ip_address_;
 
@@ -431,7 +435,6 @@ private:
     //@}
 };
 
-
 /// @brief Provides the ability to send NameChangeRequests via  UDP socket
 ///
 /// This class is a derivation of the NameChangeSender which is capable of
@@ -469,7 +472,6 @@ public:
     /// @brief Destructor
     virtual ~NameChangeUDPSender();
 
-
     /// @brief Opens a UDP socket using the given IOService.
     ///
     /// Creates a NameChangeUDPSocket bound to the sender's IP address
@@ -478,8 +480,7 @@ public:
     /// @param io_service the IOService which will monitor the socket.
     ///
     /// @throw NcrUDPError if the open fails.
-    virtual void open(isc::asiolink::IOService& io_service);
-
+    virtual void open(const isc::asiolink::IOServicePtr& io_service);
 
     /// @brief Closes the UDPSocket.
     ///
index 758689b835ac443c2b7aacd722d8849a6018de75..bb48609814e3c9471427a9bac8f15ae4678cb945 100644 (file)
@@ -24,6 +24,7 @@
 
 using namespace std;
 using namespace isc;
+using namespace isc::asiolink;
 using namespace isc::util;
 using namespace isc::dhcp_ddns;
 
@@ -88,9 +89,8 @@ public:
 /// 1. Given valid parameters, the listener constructor works
 TEST(NameChangeUDPListenerBasicTest, constructionTests) {
     // Verify the default constructor works.
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = LISTENER_PORT;
-    isc::asiolink::IOService io_service;
     SimpleListenHandler ncr_handler;
     // Verify that valid constructor works.
     EXPECT_NO_THROW(NameChangeUDPListener(ip_address, port, FMT_JSON,
@@ -105,9 +105,9 @@ TEST(NameChangeUDPListenerBasicTest, constructionTests) {
 /// 4. Return to the listening state after stopping
 TEST(NameChangeUDPListenerBasicTest, basicListenTests) {
     // Verify the default constructor works.
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = LISTENER_PORT;
-    isc::asiolink::IOService io_service;
+    IOServicePtr io_service(new IOService());
     SimpleListenHandler ncr_handler;
 
     NameChangeListenerPtr listener;
@@ -134,7 +134,7 @@ TEST(NameChangeUDPListenerBasicTest, basicListenTests) {
     EXPECT_TRUE(listener->isIoPending());
 
     // Verify that IO pending is false, after cancel event occurs.
-    EXPECT_NO_THROW(io_service.runOne());
+    EXPECT_NO_THROW(io_service->runOne());
     EXPECT_FALSE(listener->isIoPending());
 
     // Verify that attempting to stop listening when we are not is ok.
@@ -148,29 +148,28 @@ TEST(NameChangeUDPListenerBasicTest, basicListenTests) {
 /// @brief Compares two NameChangeRequests for equality.
 bool checkSendVsReceived(NameChangeRequestPtr sent_ncr,
                          NameChangeRequestPtr received_ncr) {
-    return ((sent_ncr && received_ncr) &&
-        (*sent_ncr == *received_ncr));
+    return ((sent_ncr && received_ncr) && (*sent_ncr == *received_ncr));
 }
 
 /// @brief Text fixture for testing NameChangeUDPListener
 class NameChangeUDPListenerTest : public virtual ::testing::Test,
                                   NameChangeListener::RequestReceiveHandler {
 public:
-    isc::asiolink::IOService io_service_;
+    IOServicePtr io_service_;
     NameChangeListener::Result result_;
     NameChangeRequestPtr sent_ncr_;
     NameChangeRequestPtr received_ncr_;
     NameChangeListenerPtr listener_;
-    isc::asiolink::IntervalTimer test_timer_;
+    IntervalTimer test_timer_;
 
     /// @brief Constructor
     //
     // Instantiates the listener member and the test timer. The timer is used
     // to ensure a test doesn't go awry and hang forever.
     NameChangeUDPListenerTest()
-        : io_service_(), result_(NameChangeListener::SUCCESS),
+        : io_service_(new IOService()), result_(NameChangeListener::SUCCESS),
           test_timer_(io_service_) {
-        isc::asiolink::IOAddress addr(TEST_ADDRESS);
+        IOAddress addr(TEST_ADDRESS);
         listener_.reset(new NameChangeUDPListener(addr, LISTENER_PORT,
                                               FMT_JSON, *this, true));
 
@@ -197,7 +196,7 @@ public:
 
         // Create a UDP socket through which our "sender" will send the NCR.
         boost::asio::ip::udp::socket
-            udp_socket(io_service_.getInternalIOService(), boost::asio::ip::udp::v4());
+            udp_socket(io_service_->getInternalIOService(), boost::asio::ip::udp::v4());
 
         // Create an endpoint pointed at the listener.
         boost::asio::ip::udp::endpoint
@@ -228,7 +227,7 @@ public:
     ///
     /// This callback stops all running (hanging) tasks on IO service.
     void testTimeoutHandler() {
-        io_service_.stop();
+        io_service_->stop();
         FAIL() << "Test timeout hit.";
     }
 };
@@ -252,7 +251,7 @@ TEST_F(NameChangeUDPListenerTest, basicReceiveTests) {
         ASSERT_NO_THROW(sendNcr(valid_msgs[i]));
 
         // Execute no more then one event, which should be receive complete.
-        EXPECT_NO_THROW(io_service_.runOne());
+        EXPECT_NO_THROW(io_service_->runOne());
 
         // Verify the "application" status value for a successful complete.
         EXPECT_EQ(NameChangeListener::SUCCESS, result_);
@@ -268,7 +267,7 @@ TEST_F(NameChangeUDPListenerTest, basicReceiveTests) {
     EXPECT_FALSE(listener_->amListening());
 
     // Verify that IO pending is false, after cancel event occurs.
-    EXPECT_NO_THROW(io_service_.runOne());
+    EXPECT_NO_THROW(io_service_->runOne());
     EXPECT_FALSE(listener_->isIoPending());
 }
 
@@ -312,9 +311,8 @@ public:
 /// 3. Default construction provides default max queue size
 /// 4. Construction with a custom max queue size works
 TEST_F(NameChangeUDPSenderBasicTest, constructionTests) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = SENDER_PORT;
-    isc::asiolink::IOService io_service;
     SimpleSendHandler ncr_handler;
 
     // Verify that constructing with an queue size of zero is not allowed.
@@ -349,9 +347,8 @@ TEST_F(NameChangeUDPSenderBasicTest, constructionTestsMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = SENDER_PORT;
-    isc::asiolink::IOService io_service;
     SimpleSendHandler ncr_handler;
 
     // Verify that constructing with an queue size of zero is not allowed.
@@ -378,8 +375,8 @@ TEST_F(NameChangeUDPSenderBasicTest, constructionTestsMultiThreading) {
 
 /// @brief Tests NameChangeUDPSender basic send functionality
 TEST_F(NameChangeUDPSenderBasicTest, basicSendTests) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -506,8 +503,8 @@ TEST_F(NameChangeUDPSenderBasicTest, basicSendTestsMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -632,8 +629,8 @@ TEST_F(NameChangeUDPSenderBasicTest, basicSendTestsMultiThreading) {
 /// @brief Tests that sending gets kick-started if the queue isn't empty
 /// when startSending is called.
 TEST_F(NameChangeUDPSenderBasicTest, autoStart) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -687,8 +684,8 @@ TEST_F(NameChangeUDPSenderBasicTest, autoStartMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -738,9 +735,9 @@ TEST_F(NameChangeUDPSenderBasicTest, autoStartMultiThreading) {
 
 /// @brief Tests NameChangeUDPSender basic send  with INADDR_ANY and port 0.
 TEST_F(NameChangeUDPSenderBasicTest, anyAddressSend) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOAddress any_address("0.0.0.0");
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOAddress any_address("0.0.0.0");
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -776,9 +773,9 @@ TEST_F(NameChangeUDPSenderBasicTest, anyAddressSendMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOAddress any_address("0.0.0.0");
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOAddress any_address("0.0.0.0");
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Tests are based on a list of messages, get the count now.
@@ -811,9 +808,9 @@ TEST_F(NameChangeUDPSenderBasicTest, anyAddressSendMultiThreading) {
 
 /// @brief Test the NameChangeSender::assumeQueue method.
 TEST_F(NameChangeUDPSenderBasicTest, assumeQueue) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = SENDER_PORT;
-    isc::asiolink::IOService io_service;
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
     NameChangeRequestPtr ncr;
 
@@ -883,9 +880,9 @@ TEST_F(NameChangeUDPSenderBasicTest, assumeQueueMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
+    IOAddress ip_address(TEST_ADDRESS);
     uint32_t port = SENDER_PORT;
-    isc::asiolink::IOService io_service;
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
     NameChangeRequestPtr ncr;
 
@@ -957,20 +954,20 @@ class NameChangeUDPTest : public virtual ::testing::Test,
                           NameChangeListener::RequestReceiveHandler,
                           NameChangeSender::RequestSendHandler {
 public:
-    isc::asiolink::IOService io_service_;
+    IOServicePtr io_service_;
     NameChangeListener::Result recv_result_;
     NameChangeSender::Result send_result_;
     NameChangeListenerPtr listener_;
     NameChangeSenderPtr   sender_;
-    isc::asiolink::IntervalTimer test_timer_;
+    IntervalTimer test_timer_;
 
     std::vector<NameChangeRequestPtr> sent_ncrs_;
     std::vector<NameChangeRequestPtr> received_ncrs_;
 
     NameChangeUDPTest()
-        : io_service_(), recv_result_(NameChangeListener::SUCCESS),
+        : io_service_(new IOService()), recv_result_(NameChangeListener::SUCCESS),
           send_result_(NameChangeSender::SUCCESS), test_timer_(io_service_) {
-        isc::asiolink::IOAddress addr(TEST_ADDRESS);
+        IOAddress addr(TEST_ADDRESS);
         // Create our listener instance. Note that reuse_address is true.
         listener_.reset(
             new NameChangeUDPListener(addr, LISTENER_PORT, FMT_JSON,
@@ -1019,7 +1016,7 @@ public:
     ///
     /// This callback stops all running (hanging) tasks on IO service.
     void testTimeoutHandler() {
-        io_service_.stop();
+        io_service_->stop();
         FAIL() << "Test timeout hit.";
     }
 
@@ -1098,7 +1095,7 @@ TEST_F(NameChangeUDPTest, roundTripTest) {
 
     // Execute callbacks until we have sent and received all of messages.
     while (sender_->getQueueSize() > 0 || (received_ncrs_.size() < num_msgs)) {
-        EXPECT_NO_THROW(io_service_.runOne());
+        EXPECT_NO_THROW(io_service_->runOne());
     }
 
     // Send queue should be empty.
@@ -1116,7 +1113,7 @@ TEST_F(NameChangeUDPTest, roundTripTest) {
     EXPECT_FALSE(listener_->amListening());
 
     // Verify that IO pending is false, after cancel event occurs.
-    EXPECT_NO_THROW(io_service_.runOne());
+    EXPECT_NO_THROW(io_service_->runOne());
     EXPECT_FALSE(listener_->isIoPending());
 
     // Verify that we can gracefully stop sending.
@@ -1152,7 +1149,7 @@ TEST_F(NameChangeUDPTest, roundTripTestMultiThreading) {
 
     // Execute callbacks until we have sent and received all of messages.
     while (sender_->getQueueSize() > 0 || (received_ncrs_.size() < num_msgs)) {
-        EXPECT_NO_THROW(io_service_.runOne());
+        EXPECT_NO_THROW(io_service_->runOne());
     }
 
     // Send queue should be empty.
@@ -1171,7 +1168,7 @@ TEST_F(NameChangeUDPTest, roundTripTestMultiThreading) {
     EXPECT_FALSE(listener_->amListening());
 
     // Verify that IO pending is false, after cancel event occurs.
-    EXPECT_NO_THROW(io_service_.runOne());
+    EXPECT_NO_THROW(io_service_->runOne());
     EXPECT_FALSE(listener_->isIoPending());
 
     // Verify that we can gracefully stop sending.
@@ -1182,8 +1179,8 @@ TEST_F(NameChangeUDPTest, roundTripTestMultiThreading) {
 // Tests error handling of a failure to mark the watch socket ready, when
 // sendRequest() is called.
 TEST_F(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequest) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
@@ -1217,8 +1214,8 @@ TEST_F(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequestMultiThreading)
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
@@ -1249,8 +1246,8 @@ TEST_F(NameChangeUDPSenderBasicTest, watchClosedBeforeSendRequestMultiThreading)
 // Tests error handling of a failure to mark the watch socket ready, when
 // sendNext() is called during completion handling.
 TEST_F(NameChangeUDPSenderBasicTest, watchClosedAfterSendRequest) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
@@ -1291,8 +1288,8 @@ TEST_F(NameChangeUDPSenderBasicTest, watchClosedAfterSendRequestMultiThreading)
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
@@ -1331,8 +1328,8 @@ TEST_F(NameChangeUDPSenderBasicTest, watchClosedAfterSendRequestMultiThreading)
 // Tests error handling of a failure to clear the watch socket during
 // completion handling.
 TEST_F(NameChangeUDPSenderBasicTest, watchSocketBadRead) {
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
@@ -1382,8 +1379,8 @@ TEST_F(NameChangeUDPSenderBasicTest, watchSocketBadReadMultiThreading) {
     // Enable multi-threading
     MultiThreadingMgr::instance().setMode(true);
 
-    isc::asiolink::IOAddress ip_address(TEST_ADDRESS);
-    isc::asiolink::IOService io_service;
+    IOAddress ip_address(TEST_ADDRESS);
+    IOServicePtr io_service(new IOService());
     SimpleSendHandler ncr_handler;
 
     // Create the sender and put into send mode.
index 807f728d405ea52b45e9713cc91a6fb76bc8fc52..cb66a44446c77ac1b324007949258444773a6574 100644 (file)
@@ -259,14 +259,14 @@ D2ClientMgr::startSender(D2ClientErrorHandler error_handler) {
     // Create a our own service instance when we are not being multiplexed
     // into an external service..
     private_io_service_.reset(new asiolink::IOService());
-    startSender(error_handler, *private_io_service_);
+    startSender(error_handler, private_io_service_);
     LOG_INFO(dhcpsrv_logger, DHCPSRV_DHCP_DDNS_SENDER_STARTED)
              .arg(d2_client_config_->toText());
 }
 
 void
 D2ClientMgr::startSender(D2ClientErrorHandler error_handler,
-                         isc::asiolink::IOService& io_service) {
+                         const isc::asiolink::IOServicePtr& io_service) {
     if (amSending()) {
         return;
     }
index 65c034e2358773fd45db8246c944e9595663d8f7..356f47768b86ee216d2df56ffdd3e5f64080ceaa 100644 (file)
@@ -287,7 +287,7 @@ public:
     /// @throw D2ClientError if sender instance is null. Underlying layer
     /// may throw NCRSenderExceptions exceptions.
     void startSender(D2ClientErrorHandler error_handler,
-                     isc::asiolink::IOService& io_service);
+                     const isc::asiolink::IOServicePtr& io_service);
 
     /// @brief Enables sending NameChangeRequests to kea-dhcp-ddns
     ///
index ee5b3a76d8e541bd4e302ee5c039807bdb644e25..067a6978097adb1fa4a5e758780ec6a02ec4eb7a 100644 (file)
@@ -322,7 +322,7 @@ public:
     ///
     /// @param timeout_ms Amount of time after which the method returns.
     void runTimersWithTimeout(const long timeout_ms) {
-        IntervalTimer timer(*io_service_);
+        IntervalTimer timer(io_service_);
         timer.setup([this]() {
                 io_service_->stop();
         }, timeout_ms, IntervalTimer::ONE_SHOT);
index 5b10f964e39cbb54e8d8f829398dea87d18ea4a1..b02d7841f48679df963fe0d4a6216faff03892ca 100644 (file)
@@ -117,7 +117,7 @@ CfgIfaceTest::unicastOpen(const std::string& iface_name) const {
 
 void
 CfgIfaceTest::doWait(const long timeout) {
-    asiolink::IntervalTimer timer(*io_service_);
+    asiolink::IntervalTimer timer(io_service_);
     timer.setup([this]() {
         io_service_->stop();
     }, timeout, asiolink::IntervalTimer::ONE_SHOT);
index 106e7bc4d34322193558b4049ee34e6f8e2d447b..777f070ad8564b259bb27da771c37c7a45139931 100644 (file)
@@ -21,6 +21,7 @@
 #include <sys/select.h>
 
 using namespace std;
+using namespace isc::asiolink;
 using namespace isc::dhcp;
 using namespace isc;
 namespace ph = std::placeholders;
@@ -65,10 +66,9 @@ public:
         // Update the configuration with one that is enabled.
         D2ClientConfigPtr new_cfg;
 
-        isc::asiolink::IOAddress server_ip(server_address);
-        isc::asiolink::IOAddress sender_ip(server_ip.isV4() ?
-                                           D2ClientConfig::DFT_V4_SENDER_IP :
-                                           D2ClientConfig::DFT_V6_SENDER_IP);
+        IOAddress server_ip(server_address);
+        IOAddress sender_ip(server_ip.isV4() ? D2ClientConfig::DFT_V4_SENDER_IP :
+                            D2ClientConfig::DFT_V6_SENDER_IP);
 
         ASSERT_NO_THROW(new_cfg.reset(new D2ClientConfig(true,
                                   server_ip, server_port,
@@ -296,7 +296,7 @@ TEST_F(D2ClientMgrTest, udpSendExternalIOService) {
     enableDdns("127.0.0.1", 53001, dhcp_ddns::NCR_UDP);
 
     // Place sender in send mode using an external IO service.
-    asiolink::IOService io_service;
+    asiolink::IOServicePtr io_service(new IOService());
     ASSERT_NO_THROW(startSender(getErrorHandler(), io_service));
 
     // select_fd should evaluate to NOT ready to read.
@@ -328,7 +328,7 @@ TEST_F(D2ClientMgrTest, udpSendExternalIOService6) {
     enableDdns("::1", 53001, dhcp_ddns::NCR_UDP);
 
     // Place sender in send mode using an external IO service.
-    asiolink::IOService io_service;
+    asiolink::IOServicePtr io_service(new IOService());
     ASSERT_NO_THROW(startSender(getErrorHandler(), io_service));
 
     // select_fd should evaluate to NOT ready to read.
index e9e7a2b72daf7b2c8ce2300af8874a71975d3fd1..bca014b60e673c68e57a0557ef5453b491f86b60 100644 (file)
@@ -242,7 +242,7 @@ public:
     ///
     /// @param ms Duration in milliseconds.
     void setTestTime(const uint32_t ms) {
-        IntervalTimer timer(*io_service_);
+        IntervalTimer timer(io_service_);
         timer.setup([this]() {
             io_service_->stop();
         }, ms, IntervalTimer::ONE_SHOT);
@@ -260,8 +260,8 @@ public:
     bool waitForProcess(const Memfile_LeaseMgr& lease_mgr,
                         const uint8_t timeout) {
         const uint32_t iterations_max = timeout * 1000;
-        IntervalTimer fast_path_timer(*io_service_);
-        IntervalTimer timer(*io_service_);
+        IntervalTimer fast_path_timer(io_service_);
+        IntervalTimer timer(io_service_);
         bool elapsed = false;
         timer.setup([&]() {
             io_service_->stop();
index 9dd1845d33448e47d8f0ba462a89e0879adcc507..e76474a54d731edada6e84116be46a093081e8e8 100644 (file)
@@ -165,7 +165,7 @@ TimerMgrTest::registerTimer(const std::string& timer_name, const long timer_inte
 
 void
 TimerMgrTest::doWait(const long timeout, const bool /*call_receive*/) {
-    IntervalTimer timer(*io_service_);
+    IntervalTimer timer(io_service_);
     timer.setup([this]() {
         io_service_->stop();
     }, timeout, IntervalTimer::ONE_SHOT);
index a8d970a2ad5c9d0ffafe0f1635796fc610644046..3fa1fd65608143eac5926dd539c237e3d8b269df 100644 (file)
@@ -58,7 +58,7 @@ struct TimerInfo {
     /// during the timer registration.
     /// @param interval Timer interval in milliseconds.
     /// @param mode Interval timer scheduling mode.
-    TimerInfo(asiolink::IOService& io_service,
+    TimerInfo(const asiolink::IOServicePtr& io_service,
               const asiolink::IntervalTimer::Callback& user_callback,
               const long interval,
               const asiolink::IntervalTimer::Mode& mode)
@@ -274,7 +274,7 @@ TimerMgrImpl::registerTimerInternal(const std::string& timer_name,
     // Create a structure holding the configuration for the timer. It will
     // create the instance if the IntervalTimer. It will also hold the
     // callback, interval and scheduling mode parameters.
-    TimerInfoPtr timer_info(new TimerInfo(*io_service_, callback,
+    TimerInfoPtr timer_info(new TimerInfo(io_service_, callback,
                                           interval, scheduling_mode));
 
     // Actually register the timer.
index 1f139a3cd989fb8cae181265784fc77b7ff90485..66ab6490e067c2c7e08c80e09a644dab4b8ce6f5 100644 (file)
@@ -118,7 +118,7 @@ public:
     /// @param conn_pool Back pointer to the connection pool to which this
     /// connection belongs.
     /// @param url URL associated with this connection.
-    explicit Connection(IOService& io_service,
+    explicit Connection(const IOServicePtr& io_service,
                         const TlsContextPtr& tls_context,
                         const ConnectionPoolPtr& conn_pool,
                         const Url& url);
@@ -482,7 +482,7 @@ public:
     /// connections.
     /// @param max_url_connections maximum number of concurrent
     /// connections allowed per URL.
-    explicit ConnectionPool(IOService& io_service, size_t max_url_connections)
+    explicit ConnectionPool(const IOServicePtr& io_service, size_t max_url_connections)
         : io_service_(io_service), destinations_(), pool_mutex_(),
           max_url_connections_(max_url_connections) {
     }
@@ -515,8 +515,8 @@ public:
     /// should be processed.
     void postProcessNextRequest(const Url& url,
                                 const TlsContextPtr& tls_context) {
-        io_service_.post(std::bind(&ConnectionPool::processNextRequest,
-                                   shared_from_this(), url, tls_context));
+        io_service_->post(std::bind(&ConnectionPool::processNextRequest,
+                                    shared_from_this(), url, tls_context));
     }
 
     /// @brief Queue next request for sending to the server.
@@ -1106,7 +1106,7 @@ private:
     }
 
     /// @brief A reference to the IOService that drives socket IO.
-    IOService& io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Map of Destinations by URL and TLS context.
     std::map<DestinationDescriptor, DestinationPtr> destinations_;
@@ -1118,7 +1118,7 @@ private:
     size_t max_url_connections_;
 };
 
-Connection::Connection(IOService& io_service,
+Connection::Connection(const IOServicePtr& io_service,
                        const TlsContextPtr& tls_context,
                        const ConnectionPoolPtr& conn_pool,
                        const Url& url)
@@ -1783,7 +1783,7 @@ public:
     /// the thread pool threads will be created and started, with the
     /// operational state being RUNNING.  Applicable only when thread-pool size
     /// is greater than zero.
-    HttpClientImpl(IOService& io_service, size_t thread_pool_size = 0,
+    HttpClientImpl(const IOServicePtr& io_service, size_t thread_pool_size = 0,
                    bool defer_thread_start = false)
         : thread_pool_size_(thread_pool_size), thread_pool_() {
         if (thread_pool_size_ > 0) {
@@ -1792,7 +1792,7 @@ public:
 
             // Create the connection pool. Note that we use the thread_pool_size
             // as the maximum connections per URL value.
-            conn_pool_.reset(new ConnectionPool(*thread_io_service_, thread_pool_size_));
+            conn_pool_.reset(new ConnectionPool(thread_io_service_, thread_pool_size_));
 
             // Create the thread pool.
             thread_pool_.reset(new IoServiceThreadPool(thread_io_service_, thread_pool_size_,
@@ -1947,7 +1947,7 @@ private:
     IoServiceThreadPoolPtr thread_pool_;
 };
 
-HttpClient::HttpClient(IOService& io_service, bool multi_threading_enabled,
+HttpClient::HttpClient(const IOServicePtr& io_service, bool multi_threading_enabled,
                        size_t thread_pool_size, bool defer_thread_start) {
     if (!multi_threading_enabled && thread_pool_size) {
         isc_throw(InvalidOperation,
index bea90576b7a62d9730af78e194e9148a6caa38a2..7215d4452047e63efa338af81d105b429c3bd984 100644 (file)
@@ -145,7 +145,7 @@ public:
     /// the thread pool threads will be created and started, with the
     /// operational state being RUNNING.  Applicable only when thread-pool size
     /// is greater than zero.
-    explicit HttpClient(asiolink::IOService& io_service,
+    explicit HttpClient(const asiolink::IOServicePtr& io_service,
                         bool multi_threading_enabled,
                         size_t thread_pool_size = 0,
                         bool defer_thread_start = false);
index b1e57bddbebb0ca37f683efedf81c80945fa2304..880d87df0c0ab240a4099728240834f01e26d393 100644 (file)
@@ -62,7 +62,7 @@ SocketCallback::operator()(boost::system::error_code ec, size_t length) {
     callback_(ec, length);
 }
 
-HttpConnection::HttpConnection(asiolink::IOService& io_service,
+HttpConnection::HttpConnection(const asiolink::IOServicePtr& io_service,
                                const HttpAcceptorPtr& acceptor,
                                const TlsContextPtr& tls_context,
                                HttpConnectionPool& connection_pool,
index 70109de6605233c3bfbe58711d577e7fdc86ae64..4597ca4b4829f5878cc17767e3e44249f19b4b3c 100644 (file)
@@ -241,7 +241,7 @@ public:
     /// @param request_timeout Configured timeout for a HTTP request.
     /// @param idle_timeout Timeout after which persistent HTTP connection is
     /// closed by the server.
-    HttpConnection(asiolink::IOService& io_service,
+    HttpConnection(const asiolink::IOServicePtr& io_service,
                    const HttpAcceptorPtr& acceptor,
                    const asiolink::TlsContextPtr& tls_context,
                    HttpConnectionPool& connection_pool,
index 2e6d2e1c62b4c7d6e9eb3f8c306ef1c23e32c3ee..14103de588154befef938a705b4e34060ad5a29e 100644 (file)
@@ -15,7 +15,7 @@ using namespace isc::asiolink;
 namespace isc {
 namespace http {
 
-HttpListener::HttpListener(IOService& io_service,
+HttpListener::HttpListener(const IOServicePtr& io_service,
                            const asiolink::IOAddress& server_address,
                            const unsigned short server_port,
                            const TlsContextPtr& tls_context,
index 8965f29f1c04e36a2e77b95ab0aeebbd5f3778b6..b6f49f4c97aabbafd770e72d9a5033d0d867df79 100644 (file)
@@ -96,7 +96,7 @@ public:
     ///
     /// @throw HttpListenerError when any of the specified parameters is
     /// invalid.
-    HttpListener(asiolink::IOService& io_service,
+    HttpListener(const asiolink::IOServicePtr& io_service,
                  const asiolink::IOAddress& server_address,
                  const unsigned short server_port,
                  const asiolink::TlsContextPtr& tls_context,
index fdcbdd0c8bfa4938e1fc826ac3a69942514ef1e1..80db79940524c7ae24fd989a2e1fc6ed78c57a68 100644 (file)
@@ -16,7 +16,7 @@ namespace ph = std::placeholders;
 namespace isc {
 namespace http {
 
-HttpListenerImpl::HttpListenerImpl(IOService& io_service,
+HttpListenerImpl::HttpListenerImpl(const IOServicePtr& io_service,
                                    const asiolink::IOAddress& server_address,
                                    const unsigned short server_port,
                                    const TlsContextPtr& tls_context,
index 4ad19608440ec576db135c8aab6dcf996889ac6f..0ac3de7c14bb3425ff645e4260786e07798067d2 100644 (file)
@@ -44,7 +44,7 @@ public:
     ///
     /// @throw HttpListenerError when any of the specified parameters is
     /// invalid.
-    HttpListenerImpl(asiolink::IOService& io_service,
+    HttpListenerImpl(const asiolink::IOServicePtr& io_service,
                      const asiolink::IOAddress& server_address,
                      const unsigned short server_port,
                      const asiolink::TlsContextPtr& tls_context,
@@ -102,8 +102,8 @@ protected:
     virtual HttpConnectionPtr createConnection(const HttpResponseCreatorPtr& response_creator,
                                                const HttpAcceptorCallback& callback);
 
-    /// @brief Reference to the IO service.
-    asiolink::IOService& io_service_;
+    /// @brief Pointer to the IO service.
+    asiolink::IOServicePtr io_service_;
 
     /// @brief TLS context.
     asiolink::TlsContextPtr tls_context_;
index b68c88572bee64f00fa7df47163cd0abeb4ec560..bb39f68e147077d6b5aa2b96c58cc1106cdeee16 100644 (file)
@@ -196,7 +196,7 @@ public:
 
     /// @brief Constructor.
     MultiThreadingHttpClientTest()
-        : io_service_(), client_(), listener_(), factory_(), listeners_(), factories_(),
+        : io_service_(new IOService()), client_(), listener_(), factory_(), listeners_(), factories_(),
           test_timer_(io_service_), num_threads_(0), num_batches_(0), num_listeners_(0),
           expected_requests_(0), num_in_progress_(0), num_finished_(0), paused_(false),
           pause_cnt_(0) {
@@ -229,7 +229,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs the test's IOService until the desired number of requests
@@ -237,10 +237,10 @@ public:
     void runIOService(size_t request_limit) {
         while (getRRCount() < request_limit) {
             // Always call reset() before we call run();
-            io_service_.restart();
+            io_service_->restart();
 
             // Run until a client stops the service.
-            io_service_.run();
+            io_service_->run();
         }
     }
 
@@ -354,7 +354,7 @@ public:
                     num_in_progress_ = 0;
                     test_cv_.notify_all();
                     // Stop the test's IOService.
-                    io_service_.stop();
+                    io_service_->stop();
                 } else {
                     // I'm done but others aren't wait here.
                     bool ret = test_cv_.wait_for(lck, std::chrono::seconds(10),
@@ -410,8 +410,8 @@ public:
                 std::unique_lock<std::mutex> lck(test_mutex_);
                 clientRRs_.push_back(clientRR);
                 ++num_finished_;
-                if ((num_finished_ >= expected_requests_) && !io_service_.stopped()) {
-                    io_service_.stop();
+                if ((num_finished_ >= expected_requests_) && !io_service_->stopped()) {
+                    io_service_->stop();
                 }
             }
 
@@ -773,7 +773,7 @@ public:
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Instance of the client used in the tests.
     HttpClientPtr client_;
index b8337c3d36dad5a23eaa0ecb73ca1b5a7fba2f71..d6267a0e149358472a4ecba39afae239cc3a9dc4 100644 (file)
@@ -105,7 +105,7 @@ public:
 
     /// @brief Constructor.
     HttpConnectionPoolTest()
-        : io_service_(),
+        : io_service_(new IOService()),
           acceptor_(new HttpAcceptor(io_service_)),
           connection_pool_(),
           response_creator_(new TestHttpResponseCreator()) {
@@ -216,7 +216,7 @@ public:
         ASSERT_EQ(1, pool.hasConnection(conn1));
     }
 
-    IOService io_service_;                      ///< IO service.
+    IOServicePtr io_service_;                   ///< IO service.
     HttpAcceptorPtr acceptor_;                  ///< Test acceptor.
     HttpConnectionPool connection_pool_;        ///< Test connection pool.
     HttpResponseCreatorPtr response_creator_;   ///< Test response creator.
index 47a23625db39e9f175a8bc04db036b1cec6b62b2..6572e8381ad05705c1f55627ba7a87b4aecb7bd9 100644 (file)
@@ -208,7 +208,7 @@ template<typename HttpConnectionType>
 class HttpListenerImplCustom : public HttpListenerImpl {
 public:
 
-    HttpListenerImplCustom(IOService& io_service,
+    HttpListenerImplCustom(const IOServicePtr& io_service,
                            const IOAddress& server_address,
                            const unsigned short server_port,
                            const TlsContextPtr& tls_context,
@@ -270,7 +270,7 @@ public:
     ///
     /// @throw HttpListenerError when any of the specified parameters is
     /// invalid.
-    HttpListenerCustom(IOService& io_service,
+    HttpListenerCustom(const IOServicePtr& io_service,
                        const IOAddress& server_address,
                        const unsigned short server_port,
                        const TlsContextPtr& tls_context,
@@ -308,7 +308,7 @@ public:
     /// @param request_timeout Configured timeout for a HTTP request.
     /// @param idle_timeout Timeout after which persistent HTTP connection is
     /// closed by the server.
-    HttpConnectionLongWriteBuffer(IOService& io_service,
+    HttpConnectionLongWriteBuffer(const IOServicePtr& io_service,
                                   const HttpAcceptorPtr& acceptor,
                                   const TlsContextPtr& tls_context,
                                   HttpConnectionPool& connection_pool,
@@ -355,7 +355,7 @@ public:
     /// @param request_timeout Configured timeout for a HTTP request.
     /// @param idle_timeout Timeout after which persistent HTTP connection is
     /// closed by the server.
-    HttpConnectionTransactionChange(IOService& io_service,
+    HttpConnectionTransactionChange(const IOServicePtr& io_service,
                                     const HttpAcceptorPtr& acceptor,
                                     const TlsContextPtr& tls_context,
                                     HttpConnectionPool& connection_pool,
@@ -399,7 +399,7 @@ public:
     ///
     /// Starts test timer which detects timeouts.
     HttpListenerTest()
-        : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+        : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
           test_timer_(io_service_), run_io_service_timer_(io_service_), clients_() {
         test_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler, this, true),
                           TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
@@ -435,7 +435,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs IO service with optional timeout.
@@ -443,16 +443,16 @@ public:
     /// @param timeout Optional value specifying for how long the io service
     /// should be ran.
     void runIOService(long timeout = 0) {
-        io_service_.restart();
+        io_service_->restart();
 
         if (timeout > 0) {
             run_io_service_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler,
                                                   this, false),
                                         timeout, IntervalTimer::ONE_SHOT);
         }
-        io_service_.run();
-        io_service_.restart();
-        io_service_.poll();
+        io_service_->run();
+        io_service_->restart();
+        io_service_->poll();
     }
 
     /// @brief Returns HTTP OK response expected by unit tests.
@@ -554,7 +554,7 @@ public:
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Pointer to the response creator factory.
     HttpResponseCreatorFactoryPtr factory_;
@@ -593,7 +593,7 @@ TEST_F(HttpListenerTest, listen) {
     EXPECT_EQ(httpOk(HttpVersion::HTTP_11()), client->getResponse());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 
@@ -645,7 +645,7 @@ TEST_F(HttpListenerTest, keepAlive) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that persistent HTTP connection is established by default
@@ -694,7 +694,7 @@ TEST_F(HttpListenerTest, persistentConnection) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that "keep-alive" connection is closed by the server after
@@ -753,7 +753,7 @@ TEST_F(HttpListenerTest, keepAliveTimeout) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that persistent connection is closed by the server after
@@ -810,7 +810,7 @@ TEST_F(HttpListenerTest, persistentConnectionTimeout) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that HTTP/1.1 connection remains open even if there is an
@@ -863,7 +863,7 @@ TEST_F(HttpListenerTest, persistentConnectionBadBody) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that the HTTP listener can't be started twice.
@@ -938,7 +938,7 @@ TEST_F(HttpListenerTest, invalidIdleTimeout) {
 // This test verifies that listener can't be bound to the port to which
 // other server is bound.
 TEST_F(HttpListenerTest, addressInUse) {
-    tcp::acceptor acceptor(io_service_.getInternalIOService());
+    tcp::acceptor acceptor(io_service_->getInternalIOService());
     // Use other port than SERVER_PORT to make sure that this TCP connection
     // doesn't affect subsequent tests.
     tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS),
@@ -1021,7 +1021,7 @@ public:
         listener_.stop();
         listener2_.stop();
         listener3_.stop();
-        io_service_.poll();
+        io_service_->poll();
         MultiThreadingMgr::instance().setMode(false);
     }
 
@@ -1076,7 +1076,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             EXPECT_FALSE(ec);
         }));
@@ -1090,7 +1090,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             EXPECT_FALSE(ec);
         }));
@@ -1137,7 +1137,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             EXPECT_FALSE(ec);
         }));
@@ -1151,7 +1151,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             EXPECT_FALSE(ec);
         }));
@@ -1193,7 +1193,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -1209,7 +1209,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -1250,7 +1250,7 @@ public:
                                                 request1, response1,
             [this](const boost::system::error_code& ec, const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             EXPECT_FALSE(ec);
         }));
 
@@ -1273,7 +1273,7 @@ public:
                                                 request2, response2,
             [this](const boost::system::error_code& ec, const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             EXPECT_FALSE(ec);
         }));
 
@@ -1306,7 +1306,7 @@ public:
             [this](const boost::system::error_code& ec,
                    const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             // The server should have returned an IO error.
             EXPECT_TRUE(ec);
         }));
@@ -1339,7 +1339,7 @@ public:
             [this](const boost::system::error_code& ec,
                    const HttpResponsePtr& response,
                    const std::string& parsing_error) {
-            io_service_.stop();
+            io_service_->stop();
             // There should be no IO error (answer from the server is received).
             EXPECT_FALSE(ec);
             // The response object is NULL because it couldn't be finalized.
@@ -1380,7 +1380,7 @@ public:
                             const HttpResponsePtr& response,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
                 // In this particular case we know exactly the type of the
                 // IO error returned, because the client explicitly sets this
@@ -1408,7 +1408,7 @@ public:
                             const HttpResponsePtr&,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }));
 
@@ -1439,7 +1439,7 @@ public:
                             const HttpResponsePtr& response,
                             const std::string&) {
             if (++cb_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             // In this particular case we know exactly the type of the
             // IO error returned, because the client explicitly sets this
@@ -1466,7 +1466,7 @@ public:
                             const HttpResponsePtr&,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }));
 
@@ -1560,7 +1560,7 @@ public:
                          [this](const boost::system::error_code& ec,
                                 const HttpResponsePtr&,
                                 const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
 
             // Everything should be ok.
             EXPECT_TRUE(ec.value() == 0);
@@ -1596,7 +1596,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
 
             EXPECT_FALSE(ec);
@@ -1616,7 +1616,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             EXPECT_FALSE(ec);
         },
@@ -1691,7 +1691,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num == 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
 
             EXPECT_EQ(1, monitor.connect_cnt_);      // We should have 1 connect.
@@ -1751,7 +1751,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num == 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
 
             EXPECT_EQ(2, monitor.connect_cnt_);      // We should have 1 connect.
index 3b164756f14d84cc711c5089bb16b917bcf55fd3..55568a9ad90d6c471c8ad833ee08078cd429ac1b 100644 (file)
@@ -31,10 +31,10 @@ public:
     /// @param io_service IO service to be stopped on error or completion.
     /// @param server_address string containing the IP address of the server.
     /// @param port port number of the server.
-    explicit TestHttpClient(IOService& io_service,
+    explicit TestHttpClient(const IOServicePtr& io_service,
                             const std::string& server_address = "127.0.0.1",
                             uint16_t port = 18123)
-        : io_service_(io_service.getInternalIOService()), socket_(io_service_),
+        : io_service_(io_service), socket_(io_service_->getInternalIOService()),
           buf_(), response_(), server_address_(server_address),
           server_port_(port), receive_done_(false) {
     }
@@ -65,7 +65,7 @@ public:
                 if (ec.value() != boost::asio::error::in_progress) {
                     ADD_FAILURE() << "error occurred while connecting: "
                                   << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                     return;
                 }
             }
@@ -100,7 +100,7 @@ public:
                 } else {
                     ADD_FAILURE() << "error occurred while connecting: "
                                   << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                     return;
                 }
             }
@@ -143,7 +143,7 @@ public:
                     // Error occurred, bail...
                     ADD_FAILURE() << "error occurred while receiving HTTP"
                         " response from the server: " << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }
 
@@ -156,7 +156,7 @@ public:
             // expecting.
             if (response_.find("\r\n\r\n", 0) != std::string::npos) {
                 receive_done_ = true;
-                io_service_.stop();
+                io_service_->stop();
             } else {
                 receivePartialResponse();
             }
@@ -245,8 +245,8 @@ public:
 
 private:
 
-    /// @brief Holds reference to the IO service.
-    boost::asio::io_service& io_service_;
+    /// @brief Holds pointer to the IO service.
+    isc::asiolink::IOServicePtr io_service_;
 
     /// @brief A socket used for the connection.
     boost::asio::ip::tcp::socket socket_;
index 88742144216648abc22dec6ac974c1a082b7b63a..4309a87456d88cfc717c421b93b1740c73d6a234 100644 (file)
@@ -227,7 +227,7 @@ public:
     ///
     /// Starts test timer which detects timeouts.
     HttpListenerTest()
-        : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+        : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
           test_timer_(io_service_), run_io_service_timer_(io_service_) {
         test_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler, this, true),
                           TEST_TIMEOUT, IntervalTimer::ONE_SHOT);
@@ -242,7 +242,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs IO service with optional timeout.
@@ -250,20 +250,20 @@ public:
     /// @param timeout Optional value specifying for how long the io service
     /// should be ran (ms).
     void runIOService(long timeout = 0) {
-        io_service_.restart();
+        io_service_->restart();
 
         if (timeout > 0) {
             run_io_service_timer_.setup(std::bind(&HttpListenerTest::timeoutHandler,
                                                   this, false),
                                         timeout, IntervalTimer::ONE_SHOT);
         }
-        io_service_.run();
-        io_service_.restart();
-        io_service_.poll();
+        io_service_->run();
+        io_service_->restart();
+        io_service_->poll();
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Pointer to the response creator factory.
     HttpResponseCreatorFactoryPtr factory_;
@@ -315,7 +315,7 @@ public:
         listener_->stop();
         listener2_->stop();
         listener3_->stop();
-        io_service_.poll();
+        io_service_->poll();
         MultiThreadingMgr::instance().setMode(false);
         HttpRequest::recordSubject_ = false;
         HttpRequest::recordIssuer_ = false;
@@ -372,7 +372,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -388,7 +388,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -437,7 +437,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -453,7 +453,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -501,7 +501,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -517,7 +517,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
             if (++resp_num > 1) {
-                io_service_.stop();
+                io_service_->stop();
             }
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -562,7 +562,7 @@ public:
                                                 request1, response1,
             [this](const boost::system::error_code& ec, const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
             }
@@ -587,7 +587,7 @@ public:
                                                 request2, response2,
             [this](const boost::system::error_code& ec, const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
             }
@@ -622,7 +622,7 @@ public:
             [this](const boost::system::error_code& ec,
                    const HttpResponsePtr&,
                    const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
             // The server should have returned an IO error.
             if (!ec) {
                 ADD_FAILURE() << "asyncSendRequest didn't fail";
@@ -657,7 +657,7 @@ public:
             [this](const boost::system::error_code& ec,
                    const HttpResponsePtr& response,
                    const std::string& parsing_error) {
-            io_service_.stop();
+            io_service_->stop();
             // There should be no IO error (answer from the server is received).
             if (ec) {
                 ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -700,7 +700,7 @@ public:
                             const HttpResponsePtr& response,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
                 // In this particular case we know exactly the type of the
                 // IO error returned, because the client explicitly sets this
@@ -728,7 +728,7 @@ public:
                             const HttpResponsePtr&,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }));
 
@@ -759,7 +759,7 @@ public:
                             const HttpResponsePtr& response,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
                 // In this particular case we know exactly the type of the
                 // IO error returned, because the client explicitly sets this
@@ -786,7 +786,7 @@ public:
                             const HttpResponsePtr&,
                             const std::string&) {
                 if (++cb_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }));
 
@@ -880,7 +880,7 @@ public:
                          [this](const boost::system::error_code& ec,
                                 const HttpResponsePtr&,
                                 const std::string&) {
-            io_service_.stop();
+            io_service_->stop();
 
             // Everything should be ok.
             if (ec) {
@@ -918,7 +918,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
                 if (++resp_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
 
                 if (ec) {
@@ -940,7 +940,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
                 if (++resp_num > 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
                 if (ec) {
                     ADD_FAILURE() << "asyncSendRequest failed: " << ec.message();
@@ -1017,7 +1017,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
                 if (++resp_num == 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
 
                 // We should have 1 connect.
@@ -1084,7 +1084,7 @@ public:
                               const HttpResponsePtr&,
                               const std::string&) {
                 if (++resp_num == 1) {
-                    io_service_.stop();
+                    io_service_->stop();
                 }
 
                 // We should have 1 connect.
index f5c592ce6ba8014ae7b171376e90b73d08852f78..db788ce56f052746906f0e409b66159d11ce467c 100644 (file)
@@ -212,7 +212,7 @@ template<typename HttpConnectionType>
 class HttpListenerImplCustom : public HttpListenerImpl {
 public:
 
-    HttpListenerImplCustom(IOService& io_service,
+    HttpListenerImplCustom(const IOServicePtr& io_service,
                            const IOAddress& server_address,
                            const unsigned short server_port,
                            const TlsContextPtr& tls_context,
@@ -276,7 +276,7 @@ public:
     ///
     /// @throw HttpListenerError when any of the specified parameters is
     /// invalid.
-    HttpListenerCustom(IOService& io_service,
+    HttpListenerCustom(const IOServicePtr& io_service,
                        const IOAddress& server_address,
                        const unsigned short server_port,
                        const TlsContextPtr& tls_context,
@@ -314,7 +314,7 @@ public:
     /// @param request_timeout Configured timeout for a HTTP request.
     /// @param idle_timeout Timeout after which persistent HTTP connection is
     /// closed by the server.
-    HttpConnectionLongWriteBuffer(IOService& io_service,
+    HttpConnectionLongWriteBuffer(const IOServicePtr& io_service,
                                   const HttpAcceptorPtr& acceptor,
                                   const TlsContextPtr& tls_context,
                                   HttpConnectionPool& connection_pool,
@@ -361,7 +361,7 @@ public:
     /// @param request_timeout Configured timeout for a HTTP request.
     /// @param idle_timeout Timeout after which persistent HTTP connection is
     /// closed by the server.
-    HttpConnectionTransactionChange(IOService& io_service,
+    HttpConnectionTransactionChange(const IOServicePtr& io_service,
                                     const HttpAcceptorPtr& acceptor,
                                     const TlsContextPtr& tls_context,
                                     HttpConnectionPool& connection_pool,
@@ -406,10 +406,9 @@ public:
     ///
     /// @param io_service IO service to be stopped on error.
     /// @param tls_context TLS context.
-    TestHttpClient(IOService& io_service, TlsContextPtr tls_context)
-        : io_service_(io_service.getInternalIOService()),
-          stream_(io_service_, tls_context->getContext()),
-          buf_(), response_() {
+    TestHttpClient(const IOServicePtr& io_service, TlsContextPtr tls_context)
+        : io_service_(io_service), stream_(io_service_->getInternalIOService(),
+          tls_context->getContext()), buf_(), response_() {
     }
 
     /// @brief Destructor.
@@ -438,7 +437,7 @@ public:
                 if (ec.value() != boost::asio::error::in_progress) {
                     ADD_FAILURE() << "error occurred while connecting: "
                                   << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                     return;
                 }
             }
@@ -447,7 +446,7 @@ public:
                 if (ec) {
                     ADD_FAILURE() << "error occurred during handshake: "
                                   << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                     return;
                 }
                 sendRequest(request);
@@ -483,7 +482,7 @@ public:
                 } else {
                     ADD_FAILURE() << "error occurred while connecting: "
                                   << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                     return;
                 }
             }
@@ -526,7 +525,7 @@ public:
                     // Error occurred, bail...
                     ADD_FAILURE() << "error occurred while receiving HTTP"
                         " response from the server: " << ec.message();
-                    io_service_.stop();
+                    io_service_->stop();
                 }
             }
 
@@ -538,7 +537,7 @@ public:
             // Two consecutive new lines end the part of the response we're
             // expecting.
             if (response_.find("\r\n\r\n", 0) != std::string::npos) {
-                io_service_.stop();
+                io_service_->stop();
 
             } else {
                 receivePartialResponse();
@@ -620,8 +619,8 @@ public:
 
 private:
 
-    /// @brief Holds reference to the IO service.
-    boost::asio::io_service& io_service_;
+    /// @brief Holds pointer to the IO service.
+    isc::asiolink::IOServicePtr io_service_;
 
     /// @brief A socket used for the connection.
     TlsStreamImpl stream_;
@@ -644,7 +643,7 @@ public:
     ///
     /// Starts test timer which detects timeouts.
     HttpsListenerTest()
-        : io_service_(), factory_(new TestHttpResponseCreatorFactory()),
+        : io_service_(new IOService()), factory_(new TestHttpResponseCreatorFactory()),
           test_timer_(io_service_), run_io_service_timer_(io_service_),
           clients_(), server_context_(), client_context_() {
         configServer(server_context_);
@@ -684,7 +683,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs IO service with optional timeout.
@@ -692,16 +691,16 @@ public:
     /// @param timeout Optional value specifying for how long the io service
     /// should be ran.
     void runIOService(long timeout = 0) {
-        io_service_.restart();
+        io_service_->restart();
 
         if (timeout > 0) {
             run_io_service_timer_.setup(std::bind(&HttpsListenerTest::timeoutHandler,
                                                   this, false),
                                         timeout, IntervalTimer::ONE_SHOT);
         }
-        io_service_.run();
-        io_service_.restart();
-        io_service_.poll();
+        io_service_->run();
+        io_service_->restart();
+        io_service_->poll();
     }
 
     /// @brief Returns HTTP OK response expected by unit tests.
@@ -803,7 +802,7 @@ public:
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Pointer to the response creator factory.
     HttpResponseCreatorFactoryPtr factory_;
@@ -848,7 +847,7 @@ TEST_F(HttpsListenerTest, listen) {
     EXPECT_EQ(httpOk(HttpVersion::HTTP_11()), client->getResponse());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 
@@ -900,7 +899,7 @@ TEST_F(HttpsListenerTest, keepAlive) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that persistent HTTP connection is established by default
@@ -949,7 +948,7 @@ TEST_F(HttpsListenerTest, persistentConnection) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that "keep-alive" connection is closed by the server after
@@ -1008,7 +1007,7 @@ TEST_F(HttpsListenerTest, keepAliveTimeout) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that persistent connection is closed by the server after
@@ -1065,7 +1064,7 @@ TEST_F(HttpsListenerTest, persistentConnectionTimeout) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that HTTP/1.1 connection remains open even if there is an
@@ -1118,7 +1117,7 @@ TEST_F(HttpsListenerTest, persistentConnectionBadBody) {
     EXPECT_TRUE(client->isConnectionClosed());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that the HTTP listener can't be started twice.
@@ -1193,7 +1192,7 @@ TEST_F(HttpsListenerTest, invalidIdleTimeout) {
 // This test verifies that listener can't be bound to the port to which
 // other server is bound.
 TEST_F(HttpsListenerTest, addressInUse) {
-    tcp::acceptor acceptor(io_service_.getInternalIOService());
+    tcp::acceptor acceptor(io_service_->getInternalIOService());
     // Use other port than SERVER_PORT to make sure that this TCP connection
     // doesn't affect subsequent tests.
     tcp::endpoint endpoint(address::from_string(SERVER_ADDRESS),
index c927b7521b55d1f9c23500f7db6299ac2dd36c7a..e52cbab9db5bae6725e916f15de8305ef3308b40 100644 (file)
@@ -249,7 +249,7 @@ TEST_F(DStubControllerTest, missingConfigFileArgument) {
 TEST_F(DStubControllerTest, launchRuntimeError) {
     // Use an asiolink IntervalTimer and callback to generate the
     // shutdown invocation. (Note IntervalTimer setup is in milliseconds).
-    isc::asiolink::IntervalTimer timer(*getIOService());
+    isc::asiolink::IntervalTimer timer(getIOService());
     timer.setup(genFatalErrorCallback, 2000);
 
     // Write the valid, empty, config and then run launch() for 5000 ms
@@ -337,9 +337,9 @@ TEST_F(DStubControllerTest, ioSignals) {
     controller_->recordSignalOnly(true);
 
     // Setup to raise SIGHUP in 10 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 10);
-    TimedSignal sigint(*getIOService(), SIGINT, 100);
-    TimedSignal sigterm(*getIOService(), SIGTERM, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 10);
+    TimedSignal sigint(getIOService(), SIGINT, 100);
+    TimedSignal sigterm(getIOService(), SIGTERM, 200);
 
     // Write the valid, empty, config and then run launch() for 500 ms
     time_duration elapsed_time;
@@ -362,7 +362,7 @@ TEST_F(DStubControllerTest, invalidConfigReload) {
     scheduleTimedWrite("{ \"string_test\": BOGUS JSON }", 100);
 
     // Setup to raise SIGHUP in 200 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Write the config and then run launch() for 500 ms
     // After startup, which will load the initial configuration this enters
@@ -383,7 +383,7 @@ TEST_F(DStubControllerTest, alternateParsing) {
     controller_->useAlternateParser(true);
 
     // Setup to raise SIGHUP in 200 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
 
     // Write the config and then run launch() for 500 ms
     // After startup, which will load the initial configuration this enters
@@ -406,8 +406,8 @@ TEST_F(DStubControllerTest, validConfigReload) {
     scheduleTimedWrite("{ \"string_test\": \"second value\" }", 100);
 
     // Setup to raise SIGHUP in 200 ms and another at 400 ms.
-    TimedSignal sighup(*getIOService(), SIGHUP, 200);
-    TimedSignal sighup2(*getIOService(), SIGHUP, 400);
+    TimedSignal sighup(getIOService(), SIGHUP, 200);
+    TimedSignal sighup2(getIOService(), SIGHUP, 400);
 
     // Write the config and then run launch() for 800 ms
     time_duration elapsed_time;
@@ -423,7 +423,7 @@ TEST_F(DStubControllerTest, validConfigReload) {
 // Tests that the SIGINT triggers a normal shutdown.
 TEST_F(DStubControllerTest, sigintShutdown) {
     // Setup to raise SIGHUP in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGINT, 1);
+    TimedSignal sighup(getIOService(), SIGINT, 1);
 
     // Write the config and then run launch() for 1000 ms
     time_duration elapsed_time;
@@ -452,7 +452,7 @@ TEST_F(DStubControllerTest, getVersion) {
 // Tests that the SIGTERM triggers a normal shutdown.
 TEST_F(DStubControllerTest, sigtermShutdown) {
     // Setup to raise SIGHUP in 1 ms.
-    TimedSignal sighup(*getIOService(), SIGTERM, 1);
+    TimedSignal sighup(getIOService(), SIGTERM, 1);
 
     // Write the config and then run launch() for 1000 ms
     time_duration elapsed_time;
index ec9eb3b1b8b109538720bd6b56c0e84cb8b78562..c9f23598b4097b220c5a164d5ec2af045c1258f3 100644 (file)
@@ -194,7 +194,7 @@ void
 DControllerTest::scheduleTimedWrite(const std::string& config,
                                     int write_time_ms) {
     new_cfg_content_ = config;
-    write_timer_.reset(new asiolink::IntervalTimer(*getIOService()));
+    write_timer_.reset(new asiolink::IntervalTimer(getIOService()));
     write_timer_->setup(std::bind(&DControllerTest::timedWriteCallback, this),
                         write_time_ms, asiolink::IntervalTimer::ONE_SHOT);
 }
@@ -206,7 +206,7 @@ DControllerTest::runWithConfig(const std::string& config, int run_time_ms,
     writeFile(config);
 
     // Shutdown (without error) after runtime.
-    isc::asiolink::IntervalTimer timer(*getIOService());
+    isc::asiolink::IntervalTimer timer(getIOService());
     timer.setup(genShutdownCallback, run_time_ms);
 
     // Record start time, and invoke launch().
@@ -236,7 +236,7 @@ DControllerTest::runWithConfig(const std::string& config, int run_time_ms,
     writeFile(config);
 
     // Shutdown (without error) after runtime.
-    isc::asiolink::IntervalTimer timer(*getIOService());
+    isc::asiolink::IntervalTimer timer(getIOService());
     timer.setup([&] { callback(); genShutdownCallback(); }, run_time_ms);
 
     // Record start time, and invoke launch().
index a8afa6d96512c2eb4c611000a07d794b3064645c..aca4f1d650eb8fc965f5b0360c0c00f4b22dd196 100644 (file)
@@ -57,7 +57,7 @@ MtTcpListenerMgr::start() {
         thread_io_service_.reset(new IOService());
 
         // Create a new TCPListener derivation using the factory.
-        tcp_listener_ = listener_factory_(*thread_io_service_,
+        tcp_listener_ = listener_factory_(thread_io_service_,
                                           address_,
                                           port_,
                                           tls_context_,
index 6fc2600bb76c12633f6145492d58c3fbbb0472de..cba368a5fe846f8eebbab30fa2db4383927c5158 100644 (file)
@@ -22,7 +22,7 @@ const long TCP_IDLE_CONNECTION_TIMEOUT = 300 * 1000;
 
 /// @brief Defines a factory function for creating TcpListeners.
 typedef std::function<
-        TcpListenerPtr(asiolink::IOService& io_service,
+        TcpListenerPtr(const asiolink::IOServicePtr& io_service,
                        const asiolink::IOAddress& server_address,
                        const unsigned short server_port,
                        const asiolink::TlsContextPtr& tls_context,
index d0e5393048f1ef47c96bd6d92db5dee9e3486463..0445b35a90f9d37b40e208847f6b9411473f59b3 100644 (file)
@@ -48,7 +48,7 @@ SocketCallback::operator()(boost::system::error_code ec, size_t length) {
     callback_(ec, length);
 }
 
-TcpConnection::TcpConnection(asiolink::IOService& io_service,
+TcpConnection::TcpConnection(const asiolink::IOServicePtr& io_service,
                              const TcpConnectionAcceptorPtr& acceptor,
                              const TlsContextPtr& tls_context,
                              TcpConnectionPool& connection_pool,
@@ -56,7 +56,8 @@ TcpConnection::TcpConnection(asiolink::IOService& io_service,
                              const TcpConnectionFilterCallback& connection_filter,
                              const long idle_timeout,
                              const size_t read_max /* = 32768 */)
-    : tls_context_(tls_context),
+    : io_service_(io_service),
+      tls_context_(tls_context),
       idle_timeout_(idle_timeout),
       idle_timer_(io_service),
       tcp_socket_(),
index 8b71d077f83779cdba6d76e83381d0e5241fdc79..7212d45c6af321957581866b395cfda494de4452 100644 (file)
@@ -208,7 +208,7 @@ public:
     /// @param idle_timeout Timeout after which a TCP connection is
     /// closed by the server.
     /// @param read_max maximum size of a single socket read.  Defaults to 32K.
-    TcpConnection(asiolink::IOService& io_service,
+    TcpConnection(const asiolink::IOServicePtr& io_service,
                   const TcpConnectionAcceptorPtr& acceptor,
                   const asiolink::TlsContextPtr& tls_context,
                   TcpConnectionPool& connection_pool,
@@ -422,6 +422,9 @@ protected:
         return (input_buf_.size());
     }
 
+    /// @brief The IO service used to handle events.
+    asiolink::IOServicePtr io_service_;
+
     /// @brief TLS context.
     asiolink::TlsContextPtr tls_context_;
 
index dd327ae994c32b4fa8f2b1d6189229249032054b..b668ee39a6ba5697417c21769175f1bfb8d5a04d 100644 (file)
@@ -14,7 +14,7 @@ namespace ph = std::placeholders;
 namespace isc {
 namespace tcp {
 
-TcpListener::TcpListener(IOService& io_service,
+TcpListener::TcpListener(const IOServicePtr& io_service,
                          const IOAddress& server_address,
                          const unsigned short server_port,
                          const TlsContextPtr& tls_context,
index 26f74c5ccd2d743b4406706577508c912ba452ac..0045c69a55b0a6e33f1224de92cd5d0675a062b8 100644 (file)
@@ -56,7 +56,7 @@ public:
     ///
     /// @throw TcpListenerError when any of the specified parameters is
     /// invalid.
-    TcpListener(asiolink::IOService& io_service,
+    TcpListener(const asiolink::IOServicePtr& io_service,
                 const asiolink::IOAddress& server_address,
                 const unsigned short server_port,
                 const asiolink::TlsContextPtr& tls_context,
@@ -135,8 +135,8 @@ protected:
         const TcpConnectionAcceptorCallback& acceptor_callback,
         const TcpConnectionFilterCallback& connection_filter);
 
-    /// @brief Reference to the IO service.
-    asiolink::IOService& io_service_;
+    /// @brief Pointer to the IO service.
+    asiolink::IOServicePtr io_service_;
 
     /// @brief TLS context.
     asiolink::TlsContextPtr tls_context_;
index ab561c6010c8694c5ef925b80d7419ffc95f38ee..782d7efb3e405202ae927f2acefbd1a2d6e947ca 100644 (file)
@@ -51,7 +51,7 @@ public:
     ///
     /// Starts test timer which detects timeouts, and enables multi-threading mode.
     MtTcpListenerMgrTest()
-        : mt_listener_mgr_(), io_service_(), test_timer_(io_service_),
+        : mt_listener_mgr_(), io_service_(new IOService()), test_timer_(io_service_),
           run_io_service_timer_(io_service_), clients_(), num_threads_(),
           num_clients_(), num_in_progress_(0), num_finished_(0), chunk_size_(0),
           pause_cnt_(0), response_handler_(0) {
@@ -112,7 +112,7 @@ public:
     }
 
     /// @brief TcpListener factory for MtTcpListener to instantiate new listeners.
-    TcpListenerPtr listenerFactory(asiolink::IOService& io_service,
+    TcpListenerPtr listenerFactory(const asiolink::IOServicePtr& io_service,
                                    const asiolink::IOAddress& server_address,
                                    const unsigned short server_port,
                                    const asiolink::TlsContextPtr& tls_context,
@@ -135,7 +135,7 @@ public:
     ///
     /// @param fail_on_timeout Specifies if test failure should be reported.
     void clientDone() {
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Initiates a command via a new TCP client.
@@ -206,7 +206,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Runs IO service with optional timeout.
@@ -227,10 +227,10 @@ public:
         size_t num_done = 0;
         while (num_done != request_limit) {
             // Always call restart() before we call run();
-            io_service_.restart();
+            io_service_->restart();
 
             // Run until a client stops the service.
-            io_service_.run();
+            io_service_->run();
 
             // If all the clients are done receiving, the test is done.
             num_done = 0;
@@ -428,7 +428,7 @@ public:
         // Create an MtTcpListenerMgr with prescribed number of threads.
         createMtTcpListenerMgr(num_threads,
                                std::bind(&MtTcpListenerMgrTest::synchronizedCommandHandler,
-                                          this, ph::_1));
+                                         this, ph::_1));
 
         // Start it and verify it is running.
         ASSERT_NO_THROW_LOG(mt_listener_mgr_->start());
@@ -703,7 +703,7 @@ public:
     MtTcpListenerMgrPtr mt_listener_mgr_;
 
     /// @brief IO service used in drive the test and test clients.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Asynchronous timer service to detect timeouts.
     IntervalTimer test_timer_;
index cd91f20bfae6dc37cff8165c165d8a4168ef51d2..e2b906bae63f2b4c31ab759c251d74cc29fffd3c 100644 (file)
@@ -64,7 +64,7 @@ public:
     ///
     /// Starts test timer which detects timeouts.
     TcpListenerTest()
-        : io_service_(), test_timer_(io_service_),
+        : io_service_(new IOService()), test_timer_(io_service_),
           run_io_service_timer_(io_service_),
           clients_(), clients_done_(0) {
         test_timer_.setup(std::bind(&TcpListenerTest::timeoutHandler, this, true),
@@ -129,7 +129,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Callback function each client invokes when done.
@@ -141,7 +141,7 @@ public:
         ++clients_done_;
         if (clients_done_ >= clients_.size()) {
             // They're all done or dead. Stop the service.
-            io_service_.stop();
+            io_service_->stop();
         }
     }
 
@@ -150,7 +150,7 @@ public:
     /// @param timeout Optional value specifying for how long the io service
     /// should be ran.
     void runIOService(long timeout = 0) {
-        io_service_.restart();
+        io_service_->restart();
 
         if (timeout > 0) {
             run_io_service_timer_.setup(std::bind(&TcpListenerTest::timeoutHandler,
@@ -158,9 +158,9 @@ public:
                                         timeout,
                                         IntervalTimer::ONE_SHOT);
         }
-        io_service_.run();
-        io_service_.restart();
-        io_service_.poll();
+        io_service_->run();
+        io_service_->restart();
+        io_service_->poll();
     }
 
     /// @brief Filter that denies every other connection.
@@ -182,7 +182,7 @@ public:
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Asynchronous timer service to detect timeouts.
     IntervalTimer test_timer_;
@@ -234,7 +234,7 @@ TEST_F(TcpListenerTest, listen) {
     ASSERT_EQ(expected_entries, listener.audit_trail_->getConnectionTrail(1));
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that a TCP connection can receive a complete
@@ -266,7 +266,7 @@ TEST_F(TcpListenerTest, splitReads) {
     EXPECT_FALSE(client->expectedEof());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that a TCP connection can be established and used to
@@ -295,7 +295,7 @@ TEST_F(TcpListenerTest, idleTimeoutTest) {
     EXPECT_TRUE(client->expectedEof());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 TEST_F(TcpListenerTest, multipleClientsListen) {
@@ -335,7 +335,7 @@ TEST_F(TcpListenerTest, multipleClientsListen) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // Verify that the listener handles multiple requests for multiple
@@ -388,7 +388,7 @@ TEST_F(TcpListenerTest, multipleRequetsPerClients) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // Verify that connection filtering can eliminate specific connections.
@@ -450,7 +450,7 @@ TEST_F(TcpListenerTest, filterClientsTest) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // Exercises TcpStreamRequest::postBuffer() through various
index f58e3873c310a020dd9a077f16dd22cbbcd85de2..94be72f34de4e2443bd8135bf0575a944f47d433 100644 (file)
@@ -77,13 +77,13 @@ public:
     /// @param tls_context
     /// @param server_address string containing the IP address of the server.
     /// @param port port number of the server.
-    explicit TcpTestClient(isc::asiolink::IOService& io_service,
+    explicit TcpTestClient(const isc::asiolink::IOServicePtr& io_service,
                            std::function<void()> done_callback,
                            isc::asiolink::TlsContextPtr tls_context =
                                 isc::asiolink::TlsContextPtr(),
                            const std::string& server_address = "127.0.0.1",
                            uint16_t port = 18123)
-        : io_service_(io_service.getInternalIOService()),
+        : io_service_(io_service),
           tls_context_(tls_context),
           tcp_socket_(), tls_socket_(),
           done_callback_(done_callback),
@@ -382,8 +382,8 @@ public:
 
 private:
 
-    /// @brief Holds reference to the IO service.
-    boost::asio::io_service& io_service_;
+    /// @brief Holds pointer to the IO service.
+    isc::asiolink::IOServicePtr io_service_;
 
     /// @brief TLS context.
     isc::asiolink::TlsContextPtr tls_context_;
index 2b28fb78555ab467c0808fbf4249aec9e0c3827f..44d9d372b29e77b8c8c8bc20123029135e8232bc 100644 (file)
@@ -121,7 +121,7 @@ public:
     typedef std::function<std::string(const std::string&)> ResponseHandler;
 
     /// @brief Constructor
-    TcpTestConnection(IOService& io_service,
+    TcpTestConnection(const IOServicePtr& io_service,
                       const TcpConnectionAcceptorPtr& acceptor,
                       const TlsContextPtr& tls_context,
                       TcpConnectionPool& connection_pool,
@@ -232,7 +232,7 @@ typedef boost::shared_ptr<TcpTestConnection> TcpTestConnectionPtr;
 class TcpTestListener : public TcpListener {
 public:
     /// @brief Constructor
-    TcpTestListener(IOService& io_service,
+    TcpTestListener(const IOServicePtr& io_service,
                     const IOAddress& server_address,
                     const unsigned short server_port,
                     const TlsContextPtr& tls_context,
index a3b03d6f4bdef50bcf052267ff951137791c7faa..6b7db455969f2330cd74e710e0aa1f4e8d7facdd 100644 (file)
@@ -59,7 +59,7 @@ public:
     ///
     /// Starts test timer which detects timeouts.
     TlsListenerTest()
-        : io_service_(), test_timer_(io_service_),
+        : io_service_(new IOService()), test_timer_(io_service_),
           run_io_service_timer_(io_service_),
           clients_(), clients_done_(0) {
         test_timer_.setup(std::bind(&TlsListenerTest::timeoutHandler, this, true),
@@ -139,7 +139,7 @@ public:
         if (fail_on_timeout) {
             ADD_FAILURE() << "Timeout occurred while running the test!";
         }
-        io_service_.stop();
+        io_service_->stop();
     }
 
     /// @brief Callback function each client invokes when done.
@@ -151,7 +151,7 @@ public:
         ++clients_done_;
         if (clients_done_ >= clients_.size()) {
             // They're all done or dead. Stop the service.
-            io_service_.stop();
+            io_service_->stop();
         }
     }
 
@@ -160,7 +160,7 @@ public:
     /// @param timeout Optional value specifying for how long the io service
     /// should be ran.
     void runIOService(long timeout = 0) {
-        io_service_.restart();
+        io_service_->restart();
 
         if (timeout > 0) {
             run_io_service_timer_.setup(std::bind(&TlsListenerTest::timeoutHandler,
@@ -168,9 +168,9 @@ public:
                                         timeout,
                                         IntervalTimer::ONE_SHOT);
         }
-        io_service_.run();
-        io_service_.restart();
-        io_service_.poll();
+        io_service_->run();
+        io_service_->restart();
+        io_service_->poll();
     }
 
     /// @brief Filter that denies every other connection.
@@ -192,7 +192,7 @@ public:
     }
 
     /// @brief IO service used in the tests.
-    IOService io_service_;
+    IOServicePtr io_service_;
 
     /// @brief Asynchronous timer service to detect timeouts.
     IntervalTimer test_timer_;
@@ -244,7 +244,7 @@ TEST_F(TlsListenerTest, listen) {
     ASSERT_EQ(expected_entries, listener.audit_trail_->getConnectionTrail(1));
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that a TLS connection is denied to a client
@@ -305,7 +305,7 @@ TEST_F(TlsListenerTest, splitReads) {
     EXPECT_FALSE(client->expectedEof());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that a TLS connection can be established and used to
@@ -334,7 +334,7 @@ TEST_F(TlsListenerTest, idleTimeoutTest) {
     EXPECT_TRUE(client->expectedEof());
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // This test verifies that TLS connections with multiple clients.
@@ -375,7 +375,7 @@ TEST_F(TlsListenerTest, multipleClientsListen) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // Verify that the listener handles multiple requests for multiple
@@ -428,7 +428,7 @@ TEST_F(TlsListenerTest, multipleRequetsPerClients) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 // Verify that connection filtering can eliminate specific connections.
@@ -492,7 +492,7 @@ TEST_F(TlsListenerTest, filterClientsTest) {
     }
 
     listener.stop();
-    io_service_.poll();
+    io_service_->poll();
 }
 
 }