]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2687] Made closeThisConnection virtual
authorFrancis Dupont <fdupont@isc.org>
Wed, 21 Dec 2022 19:38:18 +0000 (20:38 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 21 Dec 2022 19:38:18 +0000 (20:38 +0100)
src/lib/tcp/tcp_connection.cc
src/lib/tcp/tcp_connection.h
src/lib/tcp/tcp_connection_pool.h

index d3b5ec3f20015c009955b42885a7e3b4f7822e0b..fba602ffc30d5e776a8ed94a281305c6700faa85 100644 (file)
@@ -274,7 +274,9 @@ TcpConnection::doWrite(TcpResponsePtr response) {
             }
         }
     } catch (...) {
-        stopThisConnection();
+        // The connection is dead and there can't be a pending write as
+        // they are in sequence.
+        TcpConnection::stopThisConnection();
     }
 }
 
@@ -358,6 +360,7 @@ TcpConnection::socketReadCallback(TcpRequestPtr request,
         } else if ((ec.value() != boost::asio::error::try_again) &&
                    (ec.value() != boost::asio::error::would_block)) {
             stopThisConnection();
+            return;
 
         // We got EWOULDBLOCK or EAGAIN which indicate that we may be able to
         // read something from the socket on the next attempt. Just make sure
@@ -443,8 +446,10 @@ TcpConnection::socketWriteCallback(TcpResponsePtr response,
         // treated as fatal error.
         } else if ((ec.value() != boost::asio::error::try_again) &&
                    (ec.value() != boost::asio::error::would_block)) {
-            stopThisConnection();
-            // @todo TKM shouldn't there be a return here?
+            // The connection is dead and there can't be a pending write as
+            // they are in sequence.
+            TcpConnection::stopThisConnection();
+            return;
 
         // We got EWOULDBLOCK or EAGAIN which indicate that we may be able to
         // read something from the socket on the next attempt.
index 08d9da85fe0ae6d1773fa79d70a3a09f2bf1255d..0c8f24294e7cf626e8df75eb439d9cf41ebccd89 100644 (file)
@@ -396,10 +396,10 @@ protected:
     /// @brief Shuts down current connection.
     ///
     /// Copied from the next method @ref stopThisConnection
-    void shutdownConnection();
+    virtual void shutdownConnection();
 
     /// @brief Stops current connection.
-    void stopThisConnection();
+    virtual void stopThisConnection();
 
     /// @brief returns remote address in textual form
     std::string getRemoteEndpointAddressAsText() const;
index fa357693722f9bfe713612a5d2b0fa99406528c0..2bd88008207cb4778d10b385ca577636cb5a029e 100644 (file)
@@ -58,6 +58,9 @@ public:
     void stop(const TcpConnectionPtr& connection);
 
     /// @brief Stops all connections and removes them from the pool.
+    ///
+    /// @note This function is not thread-safe so should be called
+    /// when the thread pool is stopped.
     void stopAll();
 
     /// @brief Returns the number of connections using a given remote IP address.