diff options
author | Francis Dupont <fdupont@isc.org> | 2022-12-21 20:38:18 +0100 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2022-12-21 20:38:18 +0100 |
commit | 7db9dcd6214c3cbc8d731282ea1621067bf8b0fc (patch) | |
tree | f2533822e4c2d07dd5b3e6bb454efd944edb6d5b /src/lib/tcp | |
parent | [#2683] Made shutdown and close virtual (diff) | |
download | kea-7db9dcd6214c3cbc8d731282ea1621067bf8b0fc.tar.xz kea-7db9dcd6214c3cbc8d731282ea1621067bf8b0fc.zip |
[#2687] Made closeThisConnection virtual
Diffstat (limited to 'src/lib/tcp')
-rw-r--r-- | src/lib/tcp/tcp_connection.cc | 11 | ||||
-rw-r--r-- | src/lib/tcp/tcp_connection.h | 4 | ||||
-rw-r--r-- | src/lib/tcp/tcp_connection_pool.h | 3 |
3 files changed, 13 insertions, 5 deletions
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. |