Move SendData to Connection.

This commit is contained in:
Paul Chote
2021-05-23 15:27:51 +01:00
committed by reaperrr
parent 7c02b4d264
commit 6535411744
2 changed files with 25 additions and 25 deletions

View File

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