Skip to content

Commit

Permalink
Add ugly workaround for UDP ReceiveFrom + SocketAddress behaving diff…
Browse files Browse the repository at this point in the history
…erently on Linux
  • Loading branch information
compujuckel committed Dec 21, 2023
1 parent 2b5950b commit 51737e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion AssettoServer/Network/Udp/ACUdpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 5 additions & 1 deletion AssettoServer/Network/Udp/UdpPluginServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 51737e2

Please sign in to comment.