|
29 | 29 | * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
30 | 30 | * Portions Copyright (c) 1994, Regents of the University of California |
31 | 31 | * |
32 | | - * $Id: pqcomm.c,v 1.117 2001/03/22 03:59:30 momjian Exp $ |
| 32 | + * $Id: pqcomm.c,v 1.118 2001/07/11 19:03:07 tgl Exp $ |
33 | 33 | * |
34 | 34 | *------------------------------------------------------------------------- |
35 | 35 | */ |
|
80 | 80 | #include "miscadmin.h" |
81 | 81 |
|
82 | 82 |
|
83 | | -#ifndef SOMAXCONN |
84 | | -#define SOMAXCONN 5 /* from Linux listen(2) man page */ |
85 | | -#endif |
86 | | - |
87 | | - |
88 | 83 | static void pq_close(void); |
89 | 84 |
|
90 | 85 |
|
@@ -185,6 +180,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, |
185 | 180 | SockAddr saddr; |
186 | 181 | int fd, |
187 | 182 | err; |
| 183 | + int maxconn; |
188 | 184 | size_t len = 0; |
189 | 185 | int one = 1; |
190 | 186 |
|
@@ -350,7 +346,25 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber, |
350 | 346 | } |
351 | 347 | #endif /* HAVE_UNIX_SOCKETS */ |
352 | 348 |
|
353 | | - listen(fd, SOMAXCONN); |
| 349 | + /* |
| 350 | + * Select appropriate accept-queue length limit. PG_SOMAXCONN is |
| 351 | + * only intended to provide a clamp on the request on platforms where |
| 352 | + * an overly large request provokes a kernel error (are there any?). |
| 353 | + */ |
| 354 | + maxconn = MaxBackends * 2; |
| 355 | + if (maxconn > PG_SOMAXCONN) |
| 356 | + maxconn = PG_SOMAXCONN; |
| 357 | + |
| 358 | + err = listen(fd, maxconn); |
| 359 | + if (err < 0) |
| 360 | + { |
| 361 | + snprintf(PQerrormsg, PQERRORMSG_LENGTH, |
| 362 | + "FATAL: StreamServerPort: listen() failed: %s\n", |
| 363 | + strerror(errno)); |
| 364 | + fputs(PQerrormsg, stderr); |
| 365 | + pqdebug("%s", PQerrormsg); |
| 366 | + return STATUS_ERROR; |
| 367 | + } |
354 | 368 |
|
355 | 369 | *fdP = fd; |
356 | 370 |
|
|
0 commit comments