3030 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
3131 * Portions Copyright (c) 1994, Regents of the University of California
3232 *
33- *$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.191 2007/03/03 19:32:54 neilc Exp $
33+ *$PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.192 2007/06/04 11:59:20 mha Exp $
3434 *
3535 *-------------------------------------------------------------------------
3636 */
@@ -337,6 +337,16 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
337337continue ;
338338}
339339
340+ #ifndef WIN32
341+ /*
342+ * Without the SO_REUSEADDR flag, a new postmaster can't be started right away after
343+ * a stop or crash, giving "address already in use" error on TCP ports.
344+ *
345+ * On win32, however, this behavior only happens if the SO_EXLUSIVEADDRUSE is set.
346+ * With SO_REUSEADDR, win32 allows multiple servers to listen on the same address,
347+ * resulting in unpredictable behavior. With no flags at all, win32 behaves as
348+ * Unix with SO_REUSEADDR.
349+ */
340350if (!IS_AF_UNIX (addr -> ai_family ))
341351{
342352if ((setsockopt (fd ,SOL_SOCKET ,SO_REUSEADDR ,
@@ -349,6 +359,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
349359continue ;
350360}
351361}
362+ #endif
352363
353364#ifdef IPV6_V6ONLY
354365if (addr -> ai_family == AF_INET6 )