From 8eb4782a490271a01301c902c686a9a15eb1416b Mon Sep 17 00:00:00 2001 From: James Dunne Date: Wed, 20 Jun 2012 14:57:21 -0500 Subject: [PATCH] Fixed socket code constantly throwing exceptions about non-blocking. --- OpenRA.Game/Server/Connection.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; }