From 51737e2c2ee892bc7800df479517eaaf38a828fc Mon Sep 17 00:00:00 2001 From: compujuckel Date: Thu, 21 Dec 2023 13:32:24 +0100 Subject: [PATCH] Add ugly workaround for UDP ReceiveFrom + SocketAddress behaving differently on Linux --- AssettoServer/Network/Udp/ACUdpServer.cs | 6 +++++- AssettoServer/Network/Udp/UdpPluginServer.cs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/AssettoServer/Network/Udp/ACUdpServer.cs b/AssettoServer/Network/Udp/ACUdpServer.cs index b8de9556..8acc3968 100644 --- a/AssettoServer/Network/Udp/ACUdpServer.cs +++ b/AssettoServer/Network/Udp/ACUdpServer.cs @@ -72,7 +72,11 @@ private void ReceiveLoop(CancellationToken stoppingToken) var bytesRead = _socket.ReceiveFrom(buffer, SocketFlags.None, address); OnReceived(address, buffer, bytesRead); } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.TimedOut) { } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.TimedOut) + { + // This is a workaround because on Linux, the SocketAddress Size will be set to 0 for some reason + address.Size = address.Buffer.Length; + } catch (Exception ex) { Log.Error(ex, "Error in UDP receive loop"); diff --git a/AssettoServer/Network/Udp/UdpPluginServer.cs b/AssettoServer/Network/Udp/UdpPluginServer.cs index 06a056fb..a1d37bc1 100644 --- a/AssettoServer/Network/Udp/UdpPluginServer.cs +++ b/AssettoServer/Network/Udp/UdpPluginServer.cs @@ -152,7 +152,11 @@ private void ReceiveLoop(CancellationToken stoppingToken) Log.Information("Ignoring UDP Plugin packet from address {Address}", address); } } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.TimedOut) { } + catch (SocketException ex) when (ex.SocketErrorCode == SocketError.TimedOut) + { + // This is a workaround because on Linux, the SocketAddress Size will be set to 0 for some reason + address.Size = address.Buffer.Length; + } catch (Exception ex) { Log.Error(ex, "Error in UDP plugin receive loop");