Menu

SO_REUSEADDR and Win32

2004-01-12
2004-02-12
  • Christian Harlass

    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

     
    • David Sugar

      David Sugar - 2004-02-12

      Strange w32 behavior is no surprise...

      I think I will modify this in 1.1.1 as well.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.