aboutsummaryrefslogtreecommitdiff
path: root/src/backend/libpq/pqcomm.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-07-11 19:03:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-07-11 19:03:07 +0000
commit153f40067630bbea80385621ec09ac38c85d05af (patch)
treea4aa262a43141e41fcf10419db0cefacedbeda70 /src/backend/libpq/pqcomm.c
parentd946b2083ace11ca38468e7b02bebacfad52e3c5 (diff)
downloadpostgresql-153f40067630bbea80385621ec09ac38c85d05af.tar.gz
postgresql-153f40067630bbea80385621ec09ac38c85d05af.zip
Instead of believing SOMAXCONN from the system header files (which is
a lie on many Unixen), invoke listen() with MIN(MaxBackends*2, 10000). The clamp value 10000 is configurable in config.h.in, if that proves to be necessary --- hopefully it won't.
Diffstat (limited to 'src/backend/libpq/pqcomm.c')
-rw-r--r--src/backend/libpq/pqcomm.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index e3250862363..81c57a4e8d7 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -29,7 +29,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: pqcomm.c,v 1.117 2001/03/22 03:59:30 momjian Exp $
+ * $Id: pqcomm.c,v 1.118 2001/07/11 19:03:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -80,11 +80,6 @@
#include "miscadmin.h"
-#ifndef SOMAXCONN
-#define SOMAXCONN 5 /* from Linux listen(2) man page */
-#endif
-
-
static void pq_close(void);
@@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
SockAddr saddr;
int fd,
err;
+ int maxconn;
size_t len = 0;
int one = 1;
@@ -350,7 +346,25 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
}
#endif /* HAVE_UNIX_SOCKETS */
- listen(fd, SOMAXCONN);
+ /*
+ * Select appropriate accept-queue length limit. PG_SOMAXCONN is
+ * only intended to provide a clamp on the request on platforms where
+ * an overly large request provokes a kernel error (are there any?).
+ */
+ maxconn = MaxBackends * 2;
+ if (maxconn > PG_SOMAXCONN)
+ maxconn = PG_SOMAXCONN;
+
+ err = listen(fd, maxconn);
+ if (err < 0)
+ {
+ snprintf(PQerrormsg, PQERRORMSG_LENGTH,
+ "FATAL: StreamServerPort: listen() failed: %s\n",
+ strerror(errno));
+ fputs(PQerrormsg, stderr);
+ pqdebug("%s", PQerrormsg);
+ return STATUS_ERROR;
+ }
*fdP = fd;