diff options
author | Thomas Markwalder <tmark@isc.org> | 2022-11-16 16:47:53 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2022-11-16 16:47:53 +0100 |
commit | 52c85e2328a878eda2e6ffc29195885f11c9a289 (patch) | |
tree | 4272076fbd3e0438cef3ce32396aae8a6333fd8a /src/lib | |
parent | [#2635] Addressed cleanup comments and fixed UT (diff) | |
download | kea-52c85e2328a878eda2e6ffc29195885f11c9a289.tar.xz kea-52c85e2328a878eda2e6ffc29195885f11c9a289.zip |
[#2635] Fixed more clean up comments
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/config/tests/cmd_http_listener_unittests.cc | 4 | ||||
-rw-r--r-- | src/lib/tcp/mt_tcp_listener_mgr.cc | 6 | ||||
-rw-r--r-- | src/lib/tcp/mt_tcp_listener_mgr.h | 28 | ||||
-rw-r--r-- | src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc | 21 | ||||
-rw-r--r-- | src/lib/tcp/tests/tcp_test_client.h | 2 | ||||
-rw-r--r-- | src/lib/tcp/tests/tcp_test_listener.h | 40 |
6 files changed, 60 insertions, 41 deletions
diff --git a/src/lib/config/tests/cmd_http_listener_unittests.cc b/src/lib/config/tests/cmd_http_listener_unittests.cc index 854a471eea..0093980411 100644 --- a/src/lib/config/tests/cmd_http_listener_unittests.cc +++ b/src/lib/config/tests/cmd_http_listener_unittests.cc @@ -401,7 +401,7 @@ public: // Initiate the prescribed number of command requests. num_in_progress_ = 0; - for (auto i = 0; clients_.size() < num_clients; ++i) { + while (clients_.size() < num_clients) { ASSERT_NO_THROW_LOG(startThreadCommand()); } @@ -550,7 +550,7 @@ public: // Initiate the prescribed number of command requests. num_in_progress_ = 0; - for (auto i = 0; clients_.size() < num_clients; ++i) { + while (clients_.size() < num_clients) { ASSERT_NO_THROW_LOG(startThreadCommand()); } diff --git a/src/lib/tcp/mt_tcp_listener_mgr.cc b/src/lib/tcp/mt_tcp_listener_mgr.cc index 80faa6f477..25830f43a7 100644 --- a/src/lib/tcp/mt_tcp_listener_mgr.cc +++ b/src/lib/tcp/mt_tcp_listener_mgr.cc @@ -17,14 +17,14 @@ using namespace isc::asiolink; using namespace isc::tcp; -using namespace isc::tcp; using namespace isc::util; namespace isc { namespace tcp { MtTcpListenerMgr::MtTcpListenerMgr(TcpListenerFactory listener_factory, - const IOAddress& address, const uint16_t port, + const IOAddress& address, + const uint16_t port, const uint16_t thread_pool_size /* = 1 */, TlsContextPtr context /* = () */, TcpConnectionFilterCallback connection_filter /* = 0 */) @@ -75,7 +75,7 @@ MtTcpListenerMgr::start() { .arg(port_) .arg(tls_context_ ? "true" : "false"); } catch (const std::exception& ex) { - isc_throw(Unexpected, "MtTcpListenerMgr::run failed:" << ex.what()); + isc_throw(Unexpected, "MtTcpListenerMgr::start failed:" << ex.what()); } } diff --git a/src/lib/tcp/mt_tcp_listener_mgr.h b/src/lib/tcp/mt_tcp_listener_mgr.h index ba91e5d422..41cc1e1e42 100644 --- a/src/lib/tcp/mt_tcp_listener_mgr.h +++ b/src/lib/tcp/mt_tcp_listener_mgr.h @@ -44,16 +44,20 @@ class MtTcpListenerMgr { public: /// @brief Constructor /// - /// @param listener_factory Function for instantiating the internal TcpListener + /// @param listener_factory Function for instantiating the internal + /// TcpListener /// @param address Ip address to listen on for connections /// @param port Ip port to listen on for connections - /// @param thread_pool_size Maximum Number of threads in the thread pool. This - /// implicit dictates the maximum number of connections. - /// @param context TLS context for authenticating connections. Defaults to empty. - /// @param connection_filter Callback connections may use to filter connections by - /// their remote endpoint characteristics (e.g. ip address) - MtTcpListenerMgr(TcpListenerFactory listener_factory, const asiolink::IOAddress& address, - const uint16_t port, const uint16_t thread_pool_size = 1, + /// @param thread_pool_size Maximum Number of threads in the thread pool. + /// This implicit dictates the maximum number of connections. + /// @param context TLS context for authenticating connections. Defaults + /// to empty. + /// @param connection_filter Callback connections may use to filter + /// connections by their remote endpoint characteristics (e.g. ip address) + MtTcpListenerMgr(TcpListenerFactory listener_factory, + const asiolink::IOAddress& address, + const uint16_t port, + const uint16_t thread_pool_size = 1, asiolink::TlsContextPtr context = asiolink::TlsContextPtr(), TcpConnectionFilterCallback connection_filter = 0); @@ -181,12 +185,12 @@ private: /// @brief Callback the listener may use to reject connections during acceptance. TcpConnectionFilterCallback connection_filter_; - }; +}; - /// @brief Defines a shared pointer to MtTcpListenerMgr. - typedef boost::shared_ptr<MtTcpListenerMgr> MtTcpListenerMgrPtr; +/// @brief Defines a shared pointer to MtTcpListenerMgr. +typedef boost::shared_ptr<MtTcpListenerMgr> MtTcpListenerMgrPtr; -} // namespace isc::config +} // namespace isc::tcp } // namespace isc #endif // MT_TCP_LISTENER_MGR_H diff --git a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc index 1ebe946f06..4613ed2859 100644 --- a/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc +++ b/src/lib/tcp/tests/mt_tcp_listener_mgr_unittests.cc @@ -64,7 +64,7 @@ public: /// @brief Destructor. /// - /// Removes TCP clients, unregisters commands, disables MT. + /// Removes TCP clients and disables MT. virtual ~MtTcpListenerMgrTest() { // Wipe out the listener. mt_listener_mgr_.reset(); @@ -118,8 +118,12 @@ public: const asiolink::TlsContextPtr& tls_context, const TcpListener::IdleTimeout& idle_timeout, const TcpConnectionFilterCallback& connection_filter) { - TcpTestListenerPtr listener(new TcpTestListener(io_service, server_address, server_port, - tls_context, idle_timeout, connection_filter)); + TcpTestListenerPtr listener(new TcpTestListener(io_service, + server_address, + server_port, + tls_context, + idle_timeout, + connection_filter)); // Set the response handler the listener will pass into each connection. listener->setResponseHandler(response_handler_); return (listener); @@ -320,7 +324,7 @@ public: EXPECT_THROW(mt_listener_mgr_->stop(), MultiThreadingInvalidOperation); // We're done, ship it! - std::string str=createAnswerString(CONTROL_RESULT_SUCCESS, arguments); + std::string str = createAnswerString(CONTROL_RESULT_SUCCESS, arguments); return (str); } @@ -343,7 +347,8 @@ public: /// @param arguments Element tree of response arguments /// /// @return JSON text containing the response - std::string createAnswerString(const int status_code, ConstElementPtr arguments) { + std::string createAnswerString(const int status_code, + ConstElementPtr arguments) { ConstElementPtr answer = createAnswer(status_code, arguments); std::stringstream os; answer->toJSON(os); @@ -383,7 +388,7 @@ public: arguments->set("sign-off", Element::create("good bye")); // We're done, ship it! - std::string str=createAnswerString(CONTROL_RESULT_SUCCESS, arguments); + std::string str = createAnswerString(CONTROL_RESULT_SUCCESS, arguments); return (str); } @@ -434,7 +439,7 @@ public: // Initiate the prescribed number of command requests. num_in_progress_ = 0; - for (auto i = 0; clients_.size() < num_clients; ++i) { + while (clients_.size() < num_clients) { ASSERT_NO_THROW_LOG(startThreadCommand("I am done")); } @@ -570,7 +575,7 @@ public: // Initiate the prescribed number of command requests. num_in_progress_ = 0; - for (auto i = 0; clients_.size() < num_clients; ++i) { + while (clients_.size() < num_clients) { ASSERT_NO_THROW_LOG(startThreadCommand("I am done")); } diff --git a/src/lib/tcp/tests/tcp_test_client.h b/src/lib/tcp/tests/tcp_test_client.h index 6525cb6fd9..338ae5a1ae 100644 --- a/src/lib/tcp/tests/tcp_test_client.h +++ b/src/lib/tcp/tests/tcp_test_client.h @@ -172,7 +172,7 @@ public: receivePartialResponse(true); } - /// @brief Send part of the HTTP request. + /// @brief Send part of the request. /// /// @param request part of the request to be sent. /// @param send_length number of bytes to send. If not zero, can be used diff --git a/src/lib/tcp/tests/tcp_test_listener.h b/src/lib/tcp/tests/tcp_test_listener.h index 6e4b94c32f..a09db5f3fa 100644 --- a/src/lib/tcp/tests/tcp_test_listener.h +++ b/src/lib/tcp/tests/tcp_test_listener.h @@ -34,7 +34,9 @@ public: /// @param connection_id Id of the client to whom the entry pertains /// @param direction INBOUND for data received, OUTBOUND for data sent /// @param data string form of the data involved - AuditEntry(size_t connection_id, const AuditEntry::Direction& direction, const std::string& data) + AuditEntry(size_t connection_id, + const AuditEntry::Direction& direction, + const std::string& data) : connection_id_(connection_id), direction_(direction), data_(data) { } @@ -60,8 +62,8 @@ public: std::ostream& operator<<(std::ostream& os, const AuditEntry& entry); -/// @brief Contains the data receipt/transmission history for an arbitrary number -/// of connections. +/// @brief Contains the data receipt/transmission history for an arbitrary +/// number of connections. class AuditTrail { public: /// @brief Adds an entry to the audit trail. @@ -69,7 +71,9 @@ public: /// @param connection_id Id of the client to whom the entry pertains /// @param direction INBOUND for data received, OUTBOUND for data sent /// @param data string form of the data involved - void addEntry(size_t connection_id, const AuditEntry::Direction& direction, const std::string& data) { + void addEntry(size_t connection_id, + const AuditEntry::Direction& direction, + const std::string& data) { std::unique_lock<std::mutex> lck(mutex_); entries_.push_back(AuditEntry(connection_id, direction, data)); } @@ -81,9 +85,9 @@ public: std::list<AuditEntry> getConnectionTrail(size_t connection_id) { std::unique_lock<std::mutex> lck(mutex_); std::list<AuditEntry> conn_entries; - for (auto entry_it = entries_.begin(); entry_it != entries_.end(); ++entry_it) { - if ((*entry_it).connection_id_ == connection_id) { - conn_entries.push_back(*entry_it); + for (auto entry : entries_) { + if (entry.connection_id_ == connection_id) { + conn_entries.push_back(entry); } } @@ -94,8 +98,8 @@ public: std::string dump() { std::unique_lock<std::mutex> lck(mutex_); std::stringstream ss; - for (auto entry_it = entries_.begin(); entry_it != entries_.end(); ++entry_it) { - ss << (*entry_it) << std::endl; + for (auto entry : entries_) { + ss << entry << std::endl; } return (ss.str()); @@ -141,8 +145,8 @@ public: /// @brief Processes a completely received request. /// /// Adds the request to the audit trail, then forms and sends a response. - /// If the request is "I am done", the response is "good bye" which should instruct - /// the client to disconnect. + /// If the request is "I am done", the response is "good bye" which should + /// instruct the client to disconnect. /// /// @param request Request to process. virtual void requestReceived(TcpRequestPtr request) { @@ -215,6 +219,7 @@ private: /// @brief Provides request/response history. AuditTrailPtr audit_trail_; + /// @brief Reponse handler to pass into each connection. ResponseHandler response_handler_; }; @@ -265,10 +270,15 @@ protected: const TcpConnectionAcceptorCallback& acceptor_callback, const TcpConnectionFilterCallback& connection_filter, TcpTestConnection::ResponseHandler response_handler) { - TcpTestConnectionPtr conn(new TcpTestConnection(io_service_, acceptor_, tls_context_, - connections_, acceptor_callback, - connection_filter, idle_timeout_, - ++next_connection_id_, audit_trail_, + TcpTestConnectionPtr conn(new TcpTestConnection(io_service_, + acceptor_, + tls_context_, + connections_, + acceptor_callback, + connection_filter, + idle_timeout_, + ++next_connection_id_, + audit_trail_, response_handler)); conn->setReadMax(read_max_); return (conn); |