diff --git a/OpenRA.Game/Server/Connection.cs b/OpenRA.Game/Server/Connection.cs index 4f43cd3557..a012416de4 100644 --- a/OpenRA.Game/Server/Connection.cs +++ b/OpenRA.Game/Server/Connection.cs @@ -132,6 +132,29 @@ namespace OpenRA.Server } } + public void SendData(byte[] data) + { + var start = 0; + var length = data.Length; + + // Non-blocking sends are free to send only part of the data + while (start < length) + { + var sent = Socket.Send(data, start, length - start, SocketFlags.None, out var error); + if (error == SocketError.WouldBlock) + { + Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start); + Socket.Blocking = true; + sent = Socket.Send(data, start, length - start, SocketFlags.None); + Socket.Blocking = false; + } + else if (error != SocketError.Success) + throw new SocketException((int)error); + + start += sent; + } + } + public EndPoint EndPoint => Socket.RemoteEndPoint; } diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index 427b5f47cb..b997405763 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -101,29 +101,6 @@ namespace OpenRA.Server c.Color = pr.LockColor ? pr.Color : c.PreferredColor; } - static void SendData(Socket s, byte[] data) - { - var start = 0; - var length = data.Length; - - // Non-blocking sends are free to send only part of the data - while (start < length) - { - var sent = s.Send(data, start, length - start, SocketFlags.None, out var error); - if (error == SocketError.WouldBlock) - { - Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start); - s.Blocking = true; - sent = s.Send(data, start, length - start, SocketFlags.None); - s.Blocking = false; - } - else if (error != SocketError.Success) - throw new SocketException((int)error); - - start += sent; - } - } - public void Shutdown() { State = ServerState.ShuttingDown; @@ -389,7 +366,7 @@ namespace OpenRA.Server var ms = new MemoryStream(8); ms.WriteArray(BitConverter.GetBytes(ProtocolVersion.Handshake)); ms.WriteArray(BitConverter.GetBytes(newConn.PlayerIndex)); - SendData(newConn.Socket, ms.ToArray()); + newConn.SendData(ms.ToArray()); PreConns.Add(newConn); @@ -687,7 +664,7 @@ namespace OpenRA.Server { try { - SendData(c.Socket, frameData); + c.SendData(frameData); } catch (Exception e) {