Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0fcf740

Browse files
knizhnikkelvich
authored andcommitted
Handle keepalive parameters
1 parent044e544 commit0fcf740

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

‎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+
staticvoidMtmSetSocketOptions(intsd)
234+
{
235+
#ifdefTCP_NODELAY
236+
intoptval=1;
237+
if (setsockopt(sd,IPPROTO_TCP,TCP_NODELAY, (charconst*)&optval,sizeof(optval))<0) {
238+
elog(WARNING,"Failed to set TCP_NODELAY: %m");
239+
}
240+
#endif
241+
if (tcp_keepalives_idle) {
242+
#ifdefTCP_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+
#ifdefTCP_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+
#ifdefTCP_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+
#ifdefTCP_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
staticintMtmConnectSocket(charconst*host,intport,intmax_attempts)
234279
{
235280
structsockaddr_insock_inet;
@@ -274,12 +319,9 @@ static int MtmConnectSocket(char const* host, int port, int max_attempts)
274319
}
275320
continue;
276321
}else {
277-
intoptval=1;
278322
MtmHandshakeMessagereq;
279323
MtmArbiterMessageresp;
280-
setsockopt(sd,IPPROTO_TCP,TCP_NODELAY, (charconst*)&optval,sizeof(optval));
281-
setsockopt(sd,SOL_SOCKET,SO_KEEPALIVE, (charconst*)&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)

[8]ページ先頭

©2009-2025 Movatter.jp