On Sat, Jul 5, 2014 at 2:37 PM, Tim Hudson <t...@cryptsoft.com> wrote:
> On 5/07/2014 2:14 PM, Kurt Roeckx wrote: > > On Sat, Jul 05, 2014 at 12:45:37PM -0400, Tim Hudson wrote: > >> If you have SO_REUSEADDR set and a listener already in place you will > >> start a new listener > > No you won't. You will get a bind() error: > > socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3 > > setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 > > bind(3, {sa_family=AF_INET, sin_port=htons(3344), > sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EADDRINUSE (Address already in use) > > > > Except on windows it seems. > > All the world is not (yet) Linux :-) ... and those semantics were > defined log ago - and evolved ... and there is also REUSEPORT (added > later) and a variety of interpretations - but the base REUSEADDR can > indeed behave that way depending on what platform you are on. Linux has > its own slightly different interpretation. Some google engineering > (search) will show the the variety of confusion that this causes in > cross-platform code. > FWIW, Windows is the only platform for which Apache httpd does not enable SO_REUSEADDR prior to bind. That itself doesn't make it right, but there has been plenty of time to complain. And admins notice things like multiple instances on the same port and confusion about which instance handles which connection. As for Windows, SO_EXCLUSIVEADDRUSE looks interesting: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621(v=vs.85).aspx Incidentally, I don't readily see a Windows bind-while-TIME_WAIT discussion. And I see that httpd enables SO_REUSEADDR *after* the bind on Windows. The commit message for that doesn't lead me to believe that there was definite rhyme or reason, but it was 12 years ago so it probably doesn't hurt. I *guess* the TIME_WAIT issue doesn't hinder. > > Tim > > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > Development Mailing List openssl-dev@openssl.org > Automated List Manager majord...@openssl.org > -- Born in Roswell... married an alien... http://emptyhammock.com/ http://edjective.org/