From cc3bda37f704dffb641a19d17d447e0eeb1a6c6c Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 12 Sep 2005 02:26:33 +0000 Subject: Tweak TCP-keepalive code so that an invalid setting doesn't cause us to drop connections unceremoniously. Also some other marginal cleanups: don't query getsockopt() repeatedly if it fails, and avoid having the apparent definition of struct Port depend on which system headers you might have included or not. Oliver Jowett and Tom Lane. --- src/backend/utils/misc/guc.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/backend/utils/misc/guc.c') diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index b9e8ff3122e..1c44b0d2f77 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -10,7 +10,7 @@ * Written by Peter Eisentraut . * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.287 2005/08/29 21:38:18 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.288 2005/09/12 02:26:32 tgl Exp $ * *-------------------------------------------------------------------- */ @@ -5884,10 +5884,8 @@ assign_canonical_path(const char *newval, bool doit, GucSource source) static bool assign_tcp_keepalives_idle(int newval, bool doit, GucSource source) { - if (doit && MyProcPort != NULL) - { + if (doit) return (pq_setkeepalivesidle(newval, MyProcPort) == STATUS_OK); - } return true; } @@ -5895,18 +5893,17 @@ assign_tcp_keepalives_idle(int newval, bool doit, GucSource source) static const char * show_tcp_keepalives_idle(void) { - static char nbuf[32]; - snprintf(nbuf, sizeof(nbuf), "%d", MyProcPort == NULL ? 0 : pq_getkeepalivesidle(MyProcPort)); + static char nbuf[16]; + + snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesidle(MyProcPort)); return nbuf; } static bool assign_tcp_keepalives_interval(int newval, bool doit, GucSource source) { - if (doit && MyProcPort != NULL) - { + if (doit) return (pq_setkeepalivesinterval(newval, MyProcPort) == STATUS_OK); - } return true; } @@ -5914,18 +5911,17 @@ assign_tcp_keepalives_interval(int newval, bool doit, GucSource source) static const char * show_tcp_keepalives_interval(void) { - static char nbuf[32]; - snprintf(nbuf, sizeof(nbuf), "%d", MyProcPort == NULL ? 0 : pq_getkeepalivesinterval(MyProcPort)); + static char nbuf[16]; + + snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivesinterval(MyProcPort)); return nbuf; } static bool assign_tcp_keepalives_count(int newval, bool doit, GucSource source) { - if (doit && MyProcPort != NULL) - { + if (doit) return (pq_setkeepalivescount(newval, MyProcPort) == STATUS_OK); - } return true; } @@ -5933,9 +5929,11 @@ assign_tcp_keepalives_count(int newval, bool doit, GucSource source) static const char * show_tcp_keepalives_count(void) { - static char nbuf[32]; - snprintf(nbuf, sizeof(nbuf), "%d", MyProcPort == NULL ? 0 : pq_getkeepalivescount(MyProcPort)); + static char nbuf[16]; + + snprintf(nbuf, sizeof(nbuf), "%d", pq_getkeepalivescount(MyProcPort)); return nbuf; } + #include "guc-file.c" -- cgit v1.2.3