Fixed socket code constantly throwing exceptions about non-blocking.

This commit is contained in:
James Dunne
2012-06-20 14:57:21 -05:00
committed by Chris Forbes
parent 99eb3b046d
commit 8eb4782a49

View File

@@ -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;
}