Fall back to IPv4 if IPv6 is not supported
This commit is contained in:
parent
eff3b76aa5
commit
69d6a42089
1 changed files with 10 additions and 1 deletions
|
|
@ -401,7 +401,16 @@ namespace SimpleWeb {
|
|||
|
||||
if(!acceptor)
|
||||
acceptor = std::unique_ptr<asio::ip::tcp::acceptor>(new asio::ip::tcp::acceptor(*io_service));
|
||||
acceptor->open(endpoint.protocol());
|
||||
try {
|
||||
acceptor->open(endpoint.protocol());
|
||||
} catch (const system_error& error) {
|
||||
if(error.code() == asio::error::address_family_not_supported && config.address.empty()) {
|
||||
endpoint = asio::ip::tcp::endpoint(asio::ip::tcp::v4(), config.port);
|
||||
acceptor->open(endpoint.protocol());
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
acceptor->set_option(asio::socket_base::reuse_address(config.reuse_address));
|
||||
if(config.fast_open) {
|
||||
#if defined(__linux__) && defined(TCP_FASTOPEN)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue