From 5717e72367b753e9b3ea0efd2c5f9f63d225e688 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 17 Jul 2023 09:49:10 +0200 Subject: [PATCH] Enabled keepalive for Windows (>= Vista) --- src/base/kernel/Platform.h | 2 ++ src/base/kernel/Platform_mac.cpp | 6 ++++++ src/base/kernel/Platform_unix.cpp | 6 ++++++ src/base/kernel/Platform_win.cpp | 6 ++++++ src/base/net/stratum/Client.cpp | 7 ++++--- src/base/net/stratum/DaemonClient.cpp | 7 ++++--- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/base/kernel/Platform.h b/src/base/kernel/Platform.h index 04c212e64..b63a65fb4 100644 --- a/src/base/kernel/Platform.h +++ b/src/base/kernel/Platform.h @@ -49,6 +49,8 @@ public: static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; } static inline const String &userAgent() { return m_userAgent; } + static bool hasKeepalive(); + static bool isOnBatteryPower(); static uint64_t idleTime(); diff --git a/src/base/kernel/Platform_mac.cpp b/src/base/kernel/Platform_mac.cpp index d07e925d4..8420d1289 100644 --- a/src/base/kernel/Platform_mac.cpp +++ b/src/base/kernel/Platform_mac.cpp @@ -55,6 +55,12 @@ char *xmrig::Platform::createUserAgent() } +bool xmrig::Platform::hasKeepalive() +{ + return true; +} + + bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) { return true; diff --git a/src/base/kernel/Platform_unix.cpp b/src/base/kernel/Platform_unix.cpp index 4ffee2140..43e8a742f 100644 --- a/src/base/kernel/Platform_unix.cpp +++ b/src/base/kernel/Platform_unix.cpp @@ -70,6 +70,12 @@ char *xmrig::Platform::createUserAgent() } +bool xmrig::Platform::hasKeepalive() +{ + return true; +} + + #ifndef XMRIG_FEATURE_HWLOC #ifdef __DragonFly__ diff --git a/src/base/kernel/Platform_win.cpp b/src/base/kernel/Platform_win.cpp index 76d81ae56..ee04ee2a4 100644 --- a/src/base/kernel/Platform_win.cpp +++ b/src/base/kernel/Platform_win.cpp @@ -70,6 +70,12 @@ char *xmrig::Platform::createUserAgent() } +bool xmrig::Platform::hasKeepalive() +{ + return winOsVersion().dwMajorVersion >= 6; +} + + #ifndef XMRIG_FEATURE_HWLOC bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id) { diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index dfe2d6640..06cc94fca 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -50,6 +50,7 @@ #include "base/tools/Cvt.h" #include "base/tools/cryptonote/BlobReader.h" #include "net/JobResult.h" +#include "base/kernel/Platform.h" #ifdef _MSC_VER @@ -567,9 +568,9 @@ void xmrig::Client::connect(const sockaddr *addr) uv_tcp_init(uv_default_loop(), m_socket); uv_tcp_nodelay(m_socket, 1); -# ifndef WIN32 - uv_tcp_keepalive(m_socket, 1, 60); -# endif + if (Platform::hasKeepalive()) { + uv_tcp_keepalive(m_socket, 1, 60); + } uv_tcp_connect(req, m_socket, addr, onConnect); } diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index 9b1cdc425..b5e89d454 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -46,6 +46,7 @@ #include "base/tools/Timer.h" #include "base/tools/cryptonote/Signatures.h" #include "net/JobResult.h" +#include "base/kernel/Platform.h" #ifdef XMRIG_FEATURE_TLS @@ -358,9 +359,9 @@ void xmrig::DaemonClient::onResolved(const DnsRecords &records, int status, cons uv_tcp_init(uv_default_loop(), s); uv_tcp_nodelay(s, 1); -# ifndef WIN32 - uv_tcp_keepalive(s, 1, 60); -# endif + if (Platform::hasKeepalive()) { + uv_tcp_keepalive(s, 1, 60); + } if (m_pool.zmq_port() > 0) { delete m_ZMQSocket;