Boost C++ Libraries: Ticket #9242: I hope i can set reuseaddr property in socket initialization https://svn.boost.org/trac10/ticket/9242 <p> in asio\detail\impl\socket_ops.ipp at 1.54 at line 1288. </p> <p> origianl: socket_type socket(int af, int type, int protocol, </p> <blockquote> <p> boost::system::error_code&amp; ec) </p> </blockquote> <p> I Hope: </p> <p> socket_type socket(int af, int type, int protocol, </p> <blockquote> <p> boost::system::error_code&amp; ec, BOOL <a class="missing wiki">ReuseAddr</a>) </p> </blockquote> <p> And this is my modified code for this function: </p> <p> socket_type socket(int af, int type, int protocol, </p> <blockquote> <p> boost::system::error_code&amp; ec, BOOL <a class="missing wiki">ReuseAddr</a>) </p> </blockquote> <p> { </p> <blockquote> <p> clear_last_error(); </p> </blockquote> <table class="wiki"> <tr>#if defined(BOOST_WINDOWS) <td> defined(<span class="underline">CYGWIN</span>) </td></tr></table> <blockquote> <p> socket_type s = error_wrapper(::WSASocket(af, type, protocol, 0, 0, </p> <blockquote> <p> WSA_FLAG_OVERLAPPED), ec); </p> </blockquote> <p> if (s == invalid_socket) </p> <blockquote> <p> return s; </p> </blockquote> </blockquote> <blockquote> <p> if (af == AF_INET6) { </p> <blockquote> <p> <em> Try to enable the POSIX default behaviour of having IPV6_V6ONLY set to </em> false. This will only succeed on Windows Vista and later versions of <em> Windows, where a dual-stack IPv4/v6 implementation is available. DWORD optval = 0; ::setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, </em></p> <blockquote> <p> reinterpret_cast&lt;const char*&gt;(&amp;optval), sizeof(optval)); </p> </blockquote> </blockquote> <p> } </p> </blockquote> <blockquote> <p> <em> I hope add set SO_REUSEADDR if (<a class="missing wiki">ReuseAddr</a>) { </em></p> <blockquote> <p> DWORD optval = 1; ::setsockopt(s, SOL_SOCKET, SO_REUSEADDR, </p> <blockquote> <p> reinterpret_cast&lt;const char*&gt;(&amp;optval), sizeof(optval)); </p> </blockquote> </blockquote> <p> } .... </p> </blockquote> <p> } </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9242 Trac 1.4.3 chris_kohlhoff Mon, 05 May 2014 08:00:07 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9242#comment:1 https://svn.boost.org/trac10/ticket/9242#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Use set_option(): </p> <blockquote> <p> my_acceptor.set_option(tcp::socket::reuse_address(true)); </p> </blockquote> <p> N.B. it is set by default for the acceptor's convenience constructor. </p> Ticket