From a8f2d817d5899a886819be11271778429d7b37ea Mon Sep 17 00:00:00 2001 From: Gavin Halliday Date: Fri, 20 Dec 2024 10:22:17 +0000 Subject: [PATCH] HPCC-33147 Add a function to allow keep-alive to be explicitly set Signed-off-by: Gavin Halliday --- system/jlib/jsocket.cpp | 14 ++++++++++++-- system/jlib/jsocket.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/system/jlib/jsocket.cpp b/system/jlib/jsocket.cpp index 2f99fa77e84..19b2a4fb4be 100644 --- a/system/jlib/jsocket.cpp +++ b/system/jlib/jsocket.cpp @@ -462,7 +462,7 @@ static void queryTCPSettings() } } -extern jlib_decl bool queryKeepAlive(int &time, int &intvl, int &probes) +bool queryKeepAlive(int &time, int &intvl, int &probes) { queryTCPSettings(); if (hasKeepAlive) @@ -474,6 +474,16 @@ extern jlib_decl bool queryKeepAlive(int &time, int &intvl, int &probes) return hasKeepAlive; } +void setKeepAlive(bool enabled, int time, int intvl, int probes) +{ + CriticalBlock block(queryTCPCS); + keepAliveTime = time ? time : 200; + keepAliveInterval = intvl ? intvl : 75; + keepAliveProbes = probes ? probes : 9; + hasKeepAlive = enabled; + expertTCPSettings = INITED; +} + static int getAddressInfo(const char *name, unsigned *netaddr, bool okToLogErr); static CriticalSection queryDNSCS; @@ -1337,7 +1347,7 @@ void CSocket::setKeepAlive(bool set, int time, int intvl, int probes) optval = intvl; srtn = setsockopt(sock, IPPROTO_TCP, TCP_KEEPINTVL, (char *)&optval, optlen); if (srtn != 0) - OWARNLOG("KeepAlive probes not set"); + OWARNLOG("KeepAlive interval not set"); } if (probes >= 0) diff --git a/system/jlib/jsocket.hpp b/system/jlib/jsocket.hpp index 5e255a337c4..c8f5d6d9c8a 100644 --- a/system/jlib/jsocket.hpp +++ b/system/jlib/jsocket.hpp @@ -148,6 +148,7 @@ extern jlib_decl IpAddress &GetHostIp(IpAddress &ip); extern jlib_decl IpAddress &localHostToNIC(IpAddress &ip); extern jlib_decl bool queryKeepAlive(int &time, int &intvl, int &probes); +extern jlib_decl void setKeepAlive(bool enabled, int time=0, int intvl=0, int probes=0); class jlib_decl SocketEndpoint : extends IpAddress {