Skip to content

Commit

Permalink
Merge pull request #19369 from ghalliday/issue33147
Browse files Browse the repository at this point in the history
HPCC-33147 Add a function to allow keep-alive to be explicitly set

Reviewed-by: Mark Kelly [email protected]
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored Jan 9, 2025
2 parents 7778eb6 + a8f2d81 commit 2e72206
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions system/jlib/jsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions system/jlib/jsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 2e72206

Please sign in to comment.