aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/libpq/pqcomm.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index d9439e7fd90..ee590be1dd8 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.191 2007/03/03 19:32:54 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.192 2007/06/04 11:59:20 mha Exp $
*
*-------------------------------------------------------------------------
*/
@@ -337,6 +337,16 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
continue;
}
+#ifndef WIN32
+ /*
+ * Without the SO_REUSEADDR flag, a new postmaster can't be started right away after
+ * a stop or crash, giving "address already in use" error on TCP ports.
+ *
+ * On win32, however, this behavior only happens if the SO_EXLUSIVEADDRUSE is set.
+ * With SO_REUSEADDR, win32 allows multiple servers to listen on the same address,
+ * resulting in unpredictable behavior. With no flags at all, win32 behaves as
+ * Unix with SO_REUSEADDR.
+ */
if (!IS_AF_UNIX(addr->ai_family))
{
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
@@ -349,6 +359,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
continue;
}
}
+#endif
#ifdef IPV6_V6ONLY
if (addr->ai_family == AF_INET6)