aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-06-27 18:47:57 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-06-27 18:47:57 -0400
commitc2cb606a2ead48421398737b50614a356c3419f1 (patch)
tree3f1425779efa9de5d1800726c059c8e7f6c0f1ad /src/interfaces/libpq/fe-connect.c
parentdc777f9db3e9a5f979f4f847c96949ca5555f355 (diff)
downloadpostgresql-c2cb606a2ead48421398737b50614a356c3419f1.tar.gz
postgresql-c2cb606a2ead48421398737b50614a356c3419f1.zip
Support tcp_keepalives_idle option on Solaris.
Turns out that the socket option for this is named TCP_KEEPALIVE_THRESHOLD, at least according to the tcp(7P) man page for Solaris 11. (But since that text refers to "SunOS", it's likely pretty ancient.) It appears that the symbol TCP_KEEPALIVE does get defined on that platform, but it doesn't seem to represent a valid protocol-level socket option. This leads to bleats in the postmaster log, and no tcp_keepalives_idle functionality. Per bug #14720 from Andrey Lizenko, as well as an earlier report from Dhiraj Chawla that nobody had followed up on. The issue's been there since we added the TCP_KEEPALIVE code path in commit 5acd417c8, so back-patch to all supported branches. Discussion: https://postgr.es/m/20170627163757.25161.528@wrigleys.postgresql.org
Diffstat (limited to 'src/interfaces/libpq/fe-connect.c')
-rw-r--r--src/interfaces/libpq/fe-connect.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index ab55439db2c..17ecc355b29 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -1280,7 +1280,8 @@ setKeepalivesIdle(PGconn *conn)
if (idle < 0)
idle = 0;
-#ifdef TCP_KEEPIDLE
+#if defined(TCP_KEEPIDLE)
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
if (setsockopt(conn->sock, IPPROTO_TCP, TCP_KEEPIDLE,
(char *) &idle, sizeof(idle)) < 0)
{
@@ -1291,9 +1292,20 @@ setKeepalivesIdle(PGconn *conn)
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
return 0;
}
-#else
-#ifdef TCP_KEEPALIVE
- /* Darwin uses TCP_KEEPALIVE rather than TCP_KEEPIDLE */
+#elif defined(TCP_KEEPALIVE_THRESHOLD)
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
+ if (setsockopt(conn->sock, IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD,
+ (char *) &idle, sizeof(idle)) < 0)
+ {
+ char sebuf[256];
+
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("setsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %s\n"),
+ SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
+ return 0;
+ }
+#elif defined(TCP_KEEPALIVE)
+ /* TCP_KEEPALIVE is the name of this option on macOS */
if (setsockopt(conn->sock, IPPROTO_TCP, TCP_KEEPALIVE,
(char *) &idle, sizeof(idle)) < 0)
{
@@ -1305,7 +1317,6 @@ setKeepalivesIdle(PGconn *conn)
return 0;
}
#endif
-#endif
return 1;
}
@@ -1372,7 +1383,7 @@ setKeepalivesCount(PGconn *conn)
return 1;
}
-#else /* Win32 */
+#else /* WIN32 */
#ifdef SIO_KEEPALIVE_VALS
/*
* Enable keepalives and set the keepalive values on Win32,