From 12577df7bae70b8979c38e234d774cc900a8339e Mon Sep 17 00:00:00 2001 From: SChernykh Date: Sun, 6 Aug 2023 14:51:25 +0200 Subject: [PATCH] Disable TCP keepalive before closing socket --- src/base/net/stratum/Client.cpp | 3 +++ src/base/net/stratum/DaemonClient.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index 06cc94fca..d780a5a8a 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -344,6 +344,9 @@ bool xmrig::Client::close() setState(ClosingState); if (uv_is_closing(reinterpret_cast(m_socket)) == 0) { + if (Platform::hasKeepalive()) { + uv_tcp_keepalive(m_socket, 0, 60); + } uv_close(reinterpret_cast(m_socket), Client::onClose); } diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index b5e89d454..57d16685e 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -590,6 +590,9 @@ void xmrig::DaemonClient::retry() } if ((m_ZMQConnectionState != ZMQ_NOT_CONNECTED) && (m_ZMQConnectionState != ZMQ_DISCONNECTING)) { + if (Platform::hasKeepalive()) { + uv_tcp_keepalive(m_ZMQSocket, 0, 60); + } uv_close(reinterpret_cast(m_ZMQSocket), onZMQClose); } @@ -917,6 +920,9 @@ bool xmrig::DaemonClient::ZMQClose(bool shutdown) m_ZMQConnectionState = ZMQ_DISCONNECTING; if (uv_is_closing(reinterpret_cast(m_ZMQSocket)) == 0) { + if (Platform::hasKeepalive()) { + uv_tcp_keepalive(m_ZMQSocket, 0, 60); + } uv_close(reinterpret_cast(m_ZMQSocket), shutdown ? onZMQShutdown : onZMQClose); if (!shutdown) { retry();