Opened 9 years ago

Closed 8 years ago

#9242 closed Support Requests (invalid)

I hope i can set reuseaddr property in socket initialization

Reported by: wangyijian <wyj163mail@…> Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.54.0 Severity: Problem
Keywords: Cc:

Description

in asio\detail\impl\socket_ops.ipp at 1.54 at line 1288.

origianl: socket_type socket(int af, int type, int protocol,

boost::system::error_code& ec)

I Hope:

socket_type socket(int af, int type, int protocol,

boost::system::error_code& ec, BOOL ReuseAddr)

And this is my modified code for this function:

socket_type socket(int af, int type, int protocol,

boost::system::error_code& ec, BOOL ReuseAddr)

{

clear_last_error();

#if defined(BOOST_WINDOWS)
defined(CYGWIN)

socket_type s = error_wrapper(::WSASocket(af, type, protocol, 0, 0,

WSA_FLAG_OVERLAPPED), ec);

if (s == invalid_socket)

return s;

if (af == AF_INET6) {

Try to enable the POSIX default behaviour of having IPV6_V6ONLY set to false. This will only succeed on Windows Vista and later versions of Windows, where a dual-stack IPv4/v6 implementation is available. DWORD optval = 0; ::setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,

reinterpret_cast<const char*>(&optval), sizeof(optval));

}

I hope add set SO_REUSEADDR if (ReuseAddr) {

DWORD optval = 1; ::setsockopt(s, SOL_SOCKET, SO_REUSEADDR,

reinterpret_cast<const char*>(&optval), sizeof(optval));

} ....

}

Change History (1)

comment:1 by chris_kohlhoff, 8 years ago

Resolution: invalid
Status: newclosed

Use set_option():

my_acceptor.set_option(tcp::socket::reuse_address(true));

N.B. it is set by default for the acceptor's convenience constructor.

Note: See TracTickets for help on using tickets.