30
30
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
31
31
* Portions Copyright (c) 1994, Regents of the University of California
32
32
*
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 $
34
34
*
35
35
*-------------------------------------------------------------------------
36
36
*/
@@ -337,6 +337,16 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
337
337
continue ;
338
338
}
339
339
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
+ */
340
350
if (!IS_AF_UNIX (addr -> ai_family ))
341
351
{
342
352
if ((setsockopt (fd , SOL_SOCKET , SO_REUSEADDR ,
@@ -349,6 +359,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
349
359
continue ;
350
360
}
351
361
}
362
+ #endif
352
363
353
364
#ifdef IPV6_V6ONLY
354
365
if (addr -> ai_family == AF_INET6 )
0 commit comments