With the current cc++ code it is possible to launch a socket server twice. Extremely confusing - the 2nd "steals" all the incoming calls and the 1st "is starving".
Reason is the SO_REUSEADDR option when binding a socket (socket.cpp). See MSDN for details.
It also looks like there is a different behavior in Win32 and Linux, that's why we changed our code to this:
<code>
// CH: Not recommended with Win32, will open a 2nd server on that port, failure is the better behavior
#if defined(SO_REUSEADDR) && !defined(WIN32)
int opt = 1;
setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
</code>
Cheers,
Christian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With the current cc++ code it is possible to launch a socket server twice. Extremely confusing - the 2nd "steals" all the incoming calls and the 1st "is starving".
Reason is the SO_REUSEADDR option when binding a socket (socket.cpp). See MSDN for details.
It also looks like there is a different behavior in Win32 and Linux, that's why we changed our code to this:
<code>
// CH: Not recommended with Win32, will open a 2nd server on that port, failure is the better behavior
#if defined(SO_REUSEADDR) && !defined(WIN32)
int opt = 1;
setsockopt(so, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, (socklen_t)sizeof(opt));
#endif
</code>
Cheers,
Christian
Strange w32 behavior is no surprise...
I think I will modify this in 1.1.1 as well.