On win32, don't use SO_REUSEADDR for TCP sockets.

Per failure on buildfarm member baiji and subsequent discussion.
This commit is contained in:
Magnus Hagander 2007-06-04 11:59:27 +00:00
parent 5f32030680
commit 083094f34c

View File

@ -30,7 +30,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.175 2005/01/12 16:38:17 tgl Exp $
* $PostgreSQL: pgsql/src/backend/libpq/pqcomm.c,v 1.175.4.1 2007/06/04 11:59:27 mha Exp $
*
*-------------------------------------------------------------------------
*/
@ -338,6 +338,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,
@ -350,6 +360,7 @@ StreamServerPort(int family, char *hostName, unsigned short portNumber,
continue;
}
}
#endif
#ifdef IPV6_V6ONLY
if (addr->ai_family == AF_INET6)