diff --git a/server_http.hpp b/server_http.hpp index 0536e92..cc531c7 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -401,7 +401,16 @@ namespace SimpleWeb { if(!acceptor) acceptor = std::unique_ptr(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)