Skip to content

Commit bde6eeb

Browse files
committed
Handle keepalive parameters
1 parent 291226a commit bde6eeb

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

contrib/mmts/arbiter.c

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,51 @@ static int MtmReadSocket(int sd, void* buf, int buf_size)
230230

231231

232232

233+
static void MtmSetSocketOptions(int sd)
234+
{
235+
#ifdef TCP_NODELAY
236+
int optval = 1;
237+
if (setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char const*)&optval, sizeof(optval)) < 0) {
238+
elog(WARNING, "Failed to set TCP_NODELAY: %m");
239+
}
240+
#endif
241+
if (tcp_keepalives_idle) {
242+
#ifdef TCP_KEEPIDLE
243+
if (setsockopt(sd, IPPROTO_TCP, TCP_KEEPIDLE,
244+
(char *) &tcp_keepalives_idle, sizeof(tcp_keepalives_idle)) < 0)
245+
{
246+
elog(WARNING, "Failed to set TCP_KEEPIDLE: %m");
247+
}
248+
#else
249+
#ifdef TCP_KEEPALIVE
250+
if (setsockopt(sd, IPPROTO_TCP, TCP_KEEPALIVE,
251+
(char *) &tcp_keepalives_idle, sizeof(tcp_keepalives_idle)) < 0)
252+
{
253+
elog(WARNING, "Failed to set TCP_KEEPALIVE: %m");
254+
}
255+
#endif
256+
#endif
257+
}
258+
#ifdef TCP_KEEPINTVL
259+
if (tcp_keepalives_interval) {
260+
if (setsockopt(sd, IPPROTO_TCP, TCP_KEEPINTVL,
261+
(char *) &tcp_keepalives_interval, sizeof(tcp_keepalives_interval)) < 0)
262+
{
263+
elog(WARNING, "Failed to set TCP_KEEPINTVL: %m");
264+
}
265+
}
266+
#endif
267+
#ifdef TCP_KEEPCNT
268+
if (tcp_keepalives_count) {
269+
if (setsockopt(sd, IPPROTO_TCP, TCP_KEEPCNT,
270+
(char *) &tcp_keepalives_count, sizeof(tcp_keepalives_count)) < 0)
271+
{
272+
elog(WARNING, "Failed to set TCP_KEEPCNT: %m");
273+
}
274+
}
275+
#endif
276+
}
277+
233278
static int MtmConnectSocket(char const* host, int port, int max_attempts)
234279
{
235280
struct sockaddr_in sock_inet;
@@ -274,12 +319,9 @@ static int MtmConnectSocket(char const* host, int port, int max_attempts)
274319
}
275320
continue;
276321
} else {
277-
int optval = 1;
278322
MtmHandshakeMessage req;
279323
MtmArbiterMessage resp;
280-
setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char const*)&optval, sizeof(optval));
281-
setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char const*)&optval, sizeof(optval));
282-
324+
MtmSetSocketOptions(sd);
283325
req.hdr.code = MSG_HANDSHAKE;
284326
req.hdr.node = MtmNodeId;
285327
req.hdr.dxid = HANDSHAKE_MAGIC;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy