From a4543b30c32c0fa1d771183a3127bdc1e25259a2 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 19 Mar 2022 12:48:25 +0100 Subject: [PATCH] Network: Add fast peer disconnection in case of network error/unreachable host --- src/Nazara/Network/ENetHost.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Nazara/Network/ENetHost.cpp b/src/Nazara/Network/ENetHost.cpp index bd35c3d65..457f5242f 100644 --- a/src/Nazara/Network/ENetHost.cpp +++ b/src/Nazara/Network/ENetHost.cpp @@ -1110,7 +1110,26 @@ namespace Nz std::size_t sentLength = 0; if (!m_socket.SendMultiple(currentPeer->GetAddress(), m_buffers.data(), m_bufferCount, &sentLength)) - return -1; + { + switch (m_socket.GetLastError()) + { + case SocketError::NetworkError: + case SocketError::UnreachableHost: + { + if (!currentPeer->IsConnected()) + { + //< Network is down or unreachable (ex: IPv6 address when not supported), fails peer connection immediately + NotifyDisconnect(currentPeer, event); + return 1; + } + + [[fallthrough]]; + } + + default: + return -1; + } + } m_totalSentData += sentLength; }