From: Thomas Markwalder Date: Fri, 4 Nov 2022 18:24:34 +0000 (-0400) Subject: [#2583] Clean up X-Git-Tag: Kea-2.3.3~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e71617fb2017f403f59831d07bed36d12aa3a432;p=thirdparty%2Fkea.git [#2583] Clean up src/lib/tcp/tcp_connection.cc MAX_LOGGED_MESSAGE_SIZE -> const src/lib/tcp/tcp_connection.h Whitespace cleanup src/lib/tcp/tcp_connection_acceptor.h Fixed protector name Removed variants of HTTP and persist. --- diff --git a/src/lib/tcp/tcp_connection.cc b/src/lib/tcp/tcp_connection.cc index ab173db4a5..0b5edd5e57 100644 --- a/src/lib/tcp/tcp_connection.cc +++ b/src/lib/tcp/tcp_connection.cc @@ -23,10 +23,10 @@ namespace ph = std::placeholders; namespace { -/// @brief Maximum size of the HTTP message that can be logged. +/// @brief Maximum size of a message that can be logged. /// -/// The part of the HTTP message beyond this value is truncated. -constexpr size_t MAX_LOGGED_MESSAGE_SIZE = 1024; +/// The part of the message beyond this value is truncated. +const size_t MAX_LOGGED_MESSAGE_SIZE = 1024; } @@ -153,7 +153,7 @@ TcpConnection::asyncAccept() { // of the callback, because the underlying boost functions make copies // as needed. TcpConnectionAcceptorCallback cb = std::bind(&TcpConnection::acceptorCallback, - shared_from_this(), ph::_1); // error + shared_from_this(), ph::_1); try { TlsConnectionAcceptorPtr tls_acceptor = boost::dynamic_pointer_cast(acceptor_); diff --git a/src/lib/tcp/tcp_connection.h b/src/lib/tcp/tcp_connection.h index f3f5a8b42a..38709b1f73 100644 --- a/src/lib/tcp/tcp_connection.h +++ b/src/lib/tcp/tcp_connection.h @@ -213,7 +213,7 @@ public: /// stored. /// @param callback Callback invoked when new connection is accepted. /// @param request_timeout Configured timeout for a TCP request. - /// @param idle_timeout Timeout after which persistent TCP connection is + /// @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, @@ -380,7 +380,7 @@ protected: /// @param request Pointer to the request to be guarded by the timeout. void setupRequestTimer(TcpRequestPtr request = TcpRequestPtr()); - /// @brief Reset timer for detecting idle timeout in persistent connections. + /// @brief Reset timer for detecting idle timeout in connections. void setupIdleTimer(); /// @brief Callback invoked when the TCP Request Timeout occurs. @@ -406,7 +406,13 @@ protected: std::string getRemoteEndpointAddressAsText() const; /// @brief Returns pointer to the first byte of the input buffer. + /// + /// @throw InvalidOperation if called when the buffer is empty. unsigned char* getInputBufData() { + if (input_buf_.empty()) { + isc_throw(InvalidOperation, "TcpConnection::getInputBufData() - cannot access empty buffer"); + } + return (input_buf_.data()); } @@ -424,7 +430,7 @@ protected: /// @brief TLS context. asiolink::TlsContextPtr tls_context_; - /// @brief Timeout after which the persistent TCP connection is shut + /// @brief Timeout after which the a TCP connection is shut /// down by the server. long idle_timeout_; diff --git a/src/lib/tcp/tcp_connection_acceptor.h b/src/lib/tcp/tcp_connection_acceptor.h index 26ca543a55..028d999ec7 100644 --- a/src/lib/tcp/tcp_connection_acceptor.h +++ b/src/lib/tcp/tcp_connection_acceptor.h @@ -4,8 +4,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -#ifndef HTTP_ACCEPTOR_H -#define HTTP_ACCEPTOR_H +#ifndef TCP_CONNECTION_ACCEPTOR_H +#define TCP_CONNECTION_ACCEPTOR_H #include #include diff --git a/src/lib/tcp/tcp_listener.cc b/src/lib/tcp/tcp_listener.cc index d4269bb530..5f13892551 100644 --- a/src/lib/tcp/tcp_listener.cc +++ b/src/lib/tcp/tcp_listener.cc @@ -45,9 +45,9 @@ TcpListener::TcpListener(IOService& io_service, << request_timeout_); } - // Idle persistent connection timeout is signed and must be greater than 0. + // Idle connection timeout is signed and must be greater than 0. if (idle_timeout_ <= 0) { - isc_throw(TcpListenerError, "Invalid desired TCP idle persistent connection" + isc_throw(TcpListenerError, "Invalid desired TCP idle connection" " timeout " << idle_timeout_); } } diff --git a/src/lib/tcp/tcp_listener.h b/src/lib/tcp/tcp_listener.h index 262fac6427..b13f1a019b 100644 --- a/src/lib/tcp/tcp_listener.h +++ b/src/lib/tcp/tcp_listener.h @@ -23,7 +23,9 @@ public: isc::Exception(file, line, what) { }; }; -/// @brief ementation of the @ref TcpListener. +/// @brief Implements a class that listens for, accepts, and manages +/// TCP connections. It uses a multi-threaded connection pool, such +/// that each connection does its client's work on it's own thread. class TcpListener { public: /// @brief TCP request timeout value. @@ -62,8 +64,8 @@ public: /// @param tls_context TLS context. /// @param request_timeout Timeout maximum amount of time allotted for /// a request to be processed. - /// @param idle_timeout Timeout after which an idle persistent TCP - /// connection is closed by the server. + /// @param idle_timeout Timeout after which an idle TCP connection is + /// closed by the server. /// /// @throw TcpListenerError when any of the specified parameters is /// invalid. @@ -144,7 +146,7 @@ protected: /// @brief Maximum amount of time request to be processed. long request_timeout_; - /// @brief Timeout after which idle persistent connection is closed by + /// @brief Timeout after which idle connection is closed by /// the server. long idle_timeout_; }; diff --git a/src/lib/tcp/tcp_messages.mes b/src/lib/tcp/tcp_messages.mes index 4f5ea2fc52..3447b80a89 100644 --- a/src/lib/tcp/tcp_messages.mes +++ b/src/lib/tcp/tcp_messages.mes @@ -76,8 +76,8 @@ produced the data. This debug message is issued when a timeout occurs during the reception of request % TCP_IDLE_CONNECTION_TIMEOUT_OCCURRED closing connection with %1 as a result of a timeout -This debug message is issued when the persistent TCP connection is being -closed as a result of being idle. +This debug message is issued when the TCP connection is being closed as a +result of being idle. % TCP_PREMATURE_CONNECTION_TIMEOUT_OCCURRED premature connection timeout occurred: in transaction ? %1, transid: %2, current_transid: %3 This warning message is issued when unexpected timeout occurred during the diff --git a/src/lib/tcp/tcp_stream.cc b/src/lib/tcp/tcp_stream.cc index 290c482ef2..364b24ec82 100644 --- a/src/lib/tcp/tcp_stream.cc +++ b/src/lib/tcp/tcp_stream.cc @@ -33,19 +33,19 @@ TcpStreamRequest::postBuffer(const void* buf, const size_t nbytes) { uint16_t len = ((unsigned int)(cp[0])) << 8; len |= ((unsigned int)(cp[1])); expected_size_ = len + sizeof(len); - } + } } return (nbytes); } -std::string +std::string TcpStreamRequest::logFormatRequest(const size_t limit) const { std::stringstream output; try { size_t max = (limit && (limit < wire_data_.size()) ? limit : wire_data_.size()); - output << "expected_size_: " << expected_size_ << ", current size: " << wire_data_.size() - << ", data: " + output << "expected_size_: " << expected_size_ << ", current size: " << wire_data_.size() + << ", data: " << isc::util::str::dumpAsHex(wire_data_.data(), max); } catch (const std::exception& ex) { std::stringstream output; @@ -67,17 +67,17 @@ void TcpStreamRequest::unpack() { request_ = std::string(wire_data_.begin() + sizeof(uint16_t) , wire_data_.end()); } -void +void TcpStreamResponse::setResponseData(const std::string& response) { response_ = response; } -void +void TcpStreamResponse::appendResponseData(const std::string& response) { response_ += response; } -void +void TcpStreamResponse::pack() { wire_data_.clear(); // Prepend the length of the request.