mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Second try at fixing tcp_keepalives_idle option on Solaris.
Buildfarm evidence shows that TCP_KEEPALIVE_THRESHOLD doesn't exist
after all on Solaris < 11. This means we need to take positive action to
prevent the TCP_KEEPALIVE code path from being taken on that platform.
I've chosen to limit it with "&& defined(__darwin__)", since it's unclear
that anyone else would follow Apple's precedent of spelling the symbol
that way.
Also, follow a suggestion from Michael Paquier of eliminating code
duplication by defining a couple of intermediate symbols for the
socket option.
In passing, make some effort to reduce the number of translatable messages
by replacing "setsockopt(foo) failed" with "setsockopt(%s) failed", etc,
throughout the affected files. And update relevant documentation so
that it doesn't claim to provide an exhaustive list of the possible
socket option names.
Like the previous commit (f0256c774
), back-patch to all supported branches.
Discussion: https://postgr.es/m/20170627163757.25161.528@wrigleys.postgresql.org
This commit is contained in:
@ -94,6 +94,25 @@ static int ldapServiceLookup(const char *purl, PQconninfoOption *options,
|
||||
/* This too */
|
||||
#define ERRCODE_CANNOT_CONNECT_NOW "57P03"
|
||||
|
||||
/*
|
||||
* Cope with the various platform-specific ways to spell TCP keepalive socket
|
||||
* options. This doesn't cover Windows, which as usual does its own thing.
|
||||
*/
|
||||
#if defined(TCP_KEEPIDLE)
|
||||
/* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
|
||||
#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
|
||||
#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
|
||||
#elif defined(TCP_KEEPALIVE_THRESHOLD)
|
||||
/* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris >= 11 */
|
||||
#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
|
||||
#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
|
||||
#elif defined(TCP_KEEPALIVE) && defined(__darwin__)
|
||||
/* TCP_KEEPALIVE is the name of this option on macOS */
|
||||
/* Caution: Solaris has this symbol but it means something different */
|
||||
#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
|
||||
#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* fall back options if they are not specified by arguments or defined
|
||||
* by environment variables
|
||||
@ -1470,39 +1489,15 @@ setKeepalivesIdle(PGconn *conn)
|
||||
if (idle < 0)
|
||||
idle = 0;
|
||||
|
||||
#if defined(TCP_KEEPIDLE)
|
||||
/* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
|
||||
if (setsockopt(conn->sock, IPPROTO_TCP, TCP_KEEPIDLE,
|
||||
#ifdef PG_TCP_KEEPALIVE_IDLE
|
||||
if (setsockopt(conn->sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
|
||||
(char *) &idle, sizeof(idle)) < 0)
|
||||
{
|
||||
char sebuf[256];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(TCP_KEEPIDLE) failed: %s\n"),
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
}
|
||||
#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)
|
||||
{
|
||||
char sebuf[256];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(TCP_KEEPALIVE) failed: %s\n"),
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
PG_TCP_KEEPALIVE_IDLE_STR,
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
}
|
||||
@ -1533,7 +1528,8 @@ setKeepalivesInterval(PGconn *conn)
|
||||
char sebuf[256];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(TCP_KEEPINTVL) failed: %s\n"),
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
"TCP_KEEPINTVL",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
}
|
||||
@ -1565,7 +1561,8 @@ setKeepalivesCount(PGconn *conn)
|
||||
char sebuf[256];
|
||||
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(TCP_KEEPCNT) failed: %s\n"),
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
"TCP_KEEPCNT",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
return 0;
|
||||
}
|
||||
@ -2123,7 +2120,8 @@ keep_going: /* We will come back to here until there is
|
||||
(char *) &on, sizeof(on)) < 0)
|
||||
{
|
||||
appendPQExpBuffer(&conn->errorMessage,
|
||||
libpq_gettext("setsockopt(SO_KEEPALIVE) failed: %s\n"),
|
||||
libpq_gettext("setsockopt(%s) failed: %s\n"),
|
||||
"SO_KEEPALIVE",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
err = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user