diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index 71f0a6cab7..b9d4b07b80 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -44,6 +44,11 @@ namespace OpenRA.Server { try { + // NOTE(jsd): Poll the socket first to see if there's anything there. + // This avoids the exception with SocketErrorCode == `SocketError.WouldBlock` thrown + // from `socket.Receive(rx)`. + if (!socket.Poll(0, SelectMode.SelectRead)) break; + if (0 < (len = socket.Receive(rx))) data.AddRange(rx.Take(len)); else @@ -52,11 +57,12 @@ namespace OpenRA.Server server.DropClient(this); break; } - } catch (SocketException e) { + // NOTE(jsd): This should no longer be needed with the socket.Poll call above. if (e.SocketErrorCode == SocketError.WouldBlock) break; + server.DropClient(this); return false; }