Network: Add support for dual-stack sockets

This commit is contained in:
Lynix
2018-04-01 20:48:50 +02:00
parent 600bfc3ee6
commit 715729fc02
10 changed files with 75 additions and 11 deletions

View File

@@ -4,7 +4,7 @@
#include <Nazara/Network/AbstractSocket.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Network/Debug.hpp>
#include <Nazara/Network/Algorithm.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Network/Win32/SocketImpl.hpp>
@@ -14,6 +14,8 @@
#error Missing implementation: Socket
#endif
#include <Nazara/Network/Debug.hpp>
namespace Nz
{
/*!
@@ -187,10 +189,21 @@ namespace Nz
{
if (m_handle == SocketImpl::InvalidHandle || m_protocol != protocol)
{
SocketHandle handle = SocketImpl::Create(protocol, m_type, &m_lastError);
SocketHandle handle = SocketImpl::Create((protocol == NetProtocol_Any) ? NetProtocol_IPv6 : protocol, m_type, &m_lastError);
if (handle == SocketImpl::InvalidHandle)
return false;
if (protocol == NetProtocol_Any)
{
if (!SocketImpl::SetIPv6Only(handle, false, &m_lastError))
{
SocketImpl::Close(handle);
NazaraError("Failed to open a dual-stack socket: " + Nz::String(ErrorToString(m_lastError)));
return false;
}
}
m_protocol = protocol;
Open(handle);
}