diff options
author | Razvan Becheriu <razvan@isc.org> | 2023-12-14 19:16:52 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2024-03-05 08:50:05 +0100 |
commit | 1b070fe4b53be34d34bdbfe59ec22d65b27fa982 (patch) | |
tree | ff4fa433d4739afe2e9944b46cbab587afd302c5 /src/lib/config | |
parent | [#3271] bump version in configure.ac to 2.5.7 (diff) | |
download | kea-1b070fe4b53be34d34bdbfe59ec22d65b27fa982.tar.xz kea-1b070fe4b53be34d34bdbfe59ec22d65b27fa982.zip |
[#3190] use smart pointer to capture IOService instance
Diffstat (limited to 'src/lib/config')
-rw-r--r-- | src/lib/config/client_connection.cc | 7 | ||||
-rw-r--r-- | src/lib/config/client_connection.h | 2 | ||||
-rw-r--r-- | src/lib/config/cmd_http_listener.cc | 2 | ||||
-rw-r--r-- | src/lib/config/command_mgr.cc | 14 | ||||
-rw-r--r-- | src/lib/config/tests/client_connection_unittests.cc | 10 | ||||
-rw-r--r-- | src/lib/config/tests/cmd_http_listener_unittests.cc | 10 |
6 files changed, 20 insertions, 25 deletions
diff --git a/src/lib/config/client_connection.cc b/src/lib/config/client_connection.cc index 6217c1aae1..6f53eca261 100644 --- a/src/lib/config/client_connection.cc +++ b/src/lib/config/client_connection.cc @@ -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 diff --git a/src/lib/config/client_connection.h b/src/lib/config/client_connection.h index b88854bcd8..0cd25c66b5 100644 --- a/src/lib/config/client_connection.h +++ b/src/lib/config/client_connection.h @@ -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. /// diff --git a/src/lib/config/cmd_http_listener.cc b/src/lib/config/cmd_http_listener.cc index aa917c7824..e02f65eec0 100644 --- a/src/lib/config/cmd_http_listener.cc +++ b/src/lib/config/cmd_http_listener.cc @@ -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))); diff --git a/src/lib/config/command_mgr.cc b/src/lib/config/command_mgr.cc index 8dcb84072a..cf21a697ab 100644 --- a/src/lib/config/command_mgr.cc +++ b/src/lib/config/command_mgr.cc @@ -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 diff --git a/src/lib/config/tests/client_connection_unittests.cc b/src/lib/config/tests/client_connection_unittests.cc index 9e57575fb6..38597ce810 100644 --- a/src/lib/config/tests/client_connection_unittests.cc +++ b/src/lib/config/tests/client_connection_unittests.cc @@ -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(); } } diff --git a/src/lib/config/tests/cmd_http_listener_unittests.cc b/src/lib/config/tests/cmd_http_listener_unittests.cc index 0093980411..fbb5c8ac79 100644 --- a/src/lib/config/tests/cmd_http_listener_unittests.cc +++ b/src/lib/config/tests/cmd_http_listener_unittests.cc @@ -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_; |