aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-connect.c
diff options
context:
space:
mode:
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 8b71ae7b779..e350a242e20 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,