From: Francis Dupont Date: Wed, 21 Dec 2022 19:38:18 +0000 (+0100) Subject: [#2687] Made closeThisConnection virtual X-Git-Tag: Kea-2.3.4~83 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7db9dcd6214c3cbc8d731282ea1621067bf8b0fc;p=thirdparty%2Fkea.git [#2687] Made closeThisConnection virtual --- diff --git a/src/lib/tcp/tcp_connection.cc b/src/lib/tcp/tcp_connection.cc index d3b5ec3f20..fba602ffc3 100644 --- a/src/lib/tcp/tcp_connection.cc +++ b/src/lib/tcp/tcp_connection.cc @@ -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. diff --git a/src/lib/tcp/tcp_connection.h b/src/lib/tcp/tcp_connection.h index 08d9da85fe..0c8f24294e 100644 --- a/src/lib/tcp/tcp_connection.h +++ b/src/lib/tcp/tcp_connection.h @@ -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; diff --git a/src/lib/tcp/tcp_connection_pool.h b/src/lib/tcp/tcp_connection_pool.h index fa35769372..2bd8800820 100644 --- a/src/lib/tcp/tcp_connection_pool.h +++ b/src/lib/tcp/tcp_connection_pool.h @@ -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.