From fc4bf4e98359ebcc593f71688157be035238aedf Mon Sep 17 00:00:00 2001 From: lganzzzo Date: Mon, 17 Jan 2022 02:11:16 +0200 Subject: [PATCH] tcp::server::ConnectionProvider: Fix dual-stack sockets on Windows (#549). --- src/oatpp/network/tcp/server/ConnectionProvider.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/oatpp/network/tcp/server/ConnectionProvider.cpp b/src/oatpp/network/tcp/server/ConnectionProvider.cpp index 0fbc5fa1..adc07396 100644 --- a/src/oatpp/network/tcp/server/ConnectionProvider.cpp +++ b/src/oatpp/network/tcp/server/ConnectionProvider.cpp @@ -184,6 +184,16 @@ oatpp::v_io_handle ConnectionProvider::instantiateServer(){ if (serverHandle != INVALID_SOCKET) { + int no = 0; + + if (hints.ai_family == AF_UNSPEC || hints.ai_family == Address::IP_6) { + if (setsockopt(serverHandle, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&no, sizeof( int ) ) != 0 ) { + OATPP_LOGW("[oatpp::network::tcp::server::ConnectionProvider::instantiateServer()]", + "Warning. Failed to set %s for accepting socket: %s", "IPV6_V6ONLY", + strerror(errno)); + } + } + if (bind(serverHandle, currResult->ai_addr, (int) currResult->ai_addrlen) != SOCKET_ERROR && listen(serverHandle, SOMAXCONN) != SOCKET_ERROR) {