Move SendData to Connection.
This commit is contained in:
@@ -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;
|
public EndPoint EndPoint => Socket.RemoteEndPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,29 +101,6 @@ namespace OpenRA.Server
|
|||||||
c.Color = pr.LockColor ? pr.Color : c.PreferredColor;
|
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()
|
public void Shutdown()
|
||||||
{
|
{
|
||||||
State = ServerState.ShuttingDown;
|
State = ServerState.ShuttingDown;
|
||||||
@@ -389,7 +366,7 @@ namespace OpenRA.Server
|
|||||||
var ms = new MemoryStream(8);
|
var ms = new MemoryStream(8);
|
||||||
ms.WriteArray(BitConverter.GetBytes(ProtocolVersion.Handshake));
|
ms.WriteArray(BitConverter.GetBytes(ProtocolVersion.Handshake));
|
||||||
ms.WriteArray(BitConverter.GetBytes(newConn.PlayerIndex));
|
ms.WriteArray(BitConverter.GetBytes(newConn.PlayerIndex));
|
||||||
SendData(newConn.Socket, ms.ToArray());
|
newConn.SendData(ms.ToArray());
|
||||||
|
|
||||||
PreConns.Add(newConn);
|
PreConns.Add(newConn);
|
||||||
|
|
||||||
@@ -687,7 +664,7 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SendData(c.Socket, frameData);
|
c.SendData(frameData);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user