]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2583] Clean up
authorThomas Markwalder <tmark@isc.org>
Fri, 4 Nov 2022 18:24:34 +0000 (14:24 -0400)
committerThomas Markwalder <tmark@isc.org>
Thu, 10 Nov 2022 19:43:23 +0000 (14:43 -0500)
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.

src/lib/tcp/tcp_connection.cc
src/lib/tcp/tcp_connection.h
src/lib/tcp/tcp_connection_acceptor.h
src/lib/tcp/tcp_listener.cc
src/lib/tcp/tcp_listener.h
src/lib/tcp/tcp_messages.mes
src/lib/tcp/tcp_stream.cc

index ab173db4a526e1f9553c9c81c751d910d8525eff..0b5edd5e574e89343f0dcb8c67e73109ac37f948 100644 (file)
@@ -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<TlsConnectionAcceptor>(acceptor_);
index f3f5a8b42a7cef5130cf38905719e5773e7bf5df..38709b1f73312620323c97bb9147b8203abd0ea7 100644 (file)
@@ -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_;
 
index 26ca543a55f36356a963c3d281de79f355bbd73a..028d999ec78aa3899721dfb87172f0d7509e1d25 100644 (file)
@@ -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 <asiolink/tcp_acceptor.h>
 #include <asiolink/tls_acceptor.h>
index d4269bb5303068e515624f52d1254526cef0a2da..5f13892551eaae90f86b61a4b0859fc0d053d022 100644 (file)
@@ -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_);
     }
 }
index 262fac6427031be0a4860df25ab65b42aaee2936..b13f1a019b5833daa5417352729a9b153f64cd6d 100644 (file)
@@ -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_;
 };
index 4f5ea2fc52e19d4509152769e9c08c3ff8fd2eff..3447b80a890907c6295be6edf4b2a63f6b7ee571 100644 (file)
@@ -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
index 290c482ef215c9bfad8fb213a4278f31bb757f84..364b24ec820b7fe6ecb0fdd7a159d3b31731afc5 100644 (file)
@@ -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.