ChannelPacket.SendToTransport error checking flow improved for shorter and easier understandable code

This commit is contained in:
vis2k 2018-06-10 17:40:47 +02:00
parent 183d1464d5
commit 9f14fa37f8

View File

@ -42,26 +42,16 @@ public bool HasSpace(int numBytes)
public bool SendToTransport(NetworkConnection conn, int channelId)
{
byte error;
bool result = true;
if (!conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out error))
if (conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out error))
{
if (m_IsReliable && error == (int)NetworkError.NoResources)
{
// handled below
m_Position = 0;
return true;
}
else
{
if (LogFilter.logError) { Debug.LogError("Failed to send internal buffer channel:" + channelId + " bytesToSend:" + m_Position); }
result = false;
}
}
if (error != 0)
// NoResources and reliable? Then it will be resent, so don't reset position, just return false.
if (error == (int)NetworkError.NoResources && m_IsReliable)
{
if (m_IsReliable && error == (int)NetworkError.NoResources)
{
// this packet will be buffered by the containing ChannelBuffer, so this is not an error
#if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
@ -70,11 +60,11 @@ public bool SendToTransport(NetworkConnection conn, int channelId)
return false;
}
if (LogFilter.logError) { Debug.LogError("Send Error: " + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + m_Position); }
result = false;
}
// otherwise something unexpected happened. log the error, reset position and return.
if (LogFilter.logError) { Debug.LogError("SendToTransport failed. error:" + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + m_Position); }
m_Position = 0;
return result;
return false;
}
}
}
}