mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
ChannelPacket.SendToTransport error checking flow improved for shorter and easier understandable code
This commit is contained in:
parent
183d1464d5
commit
9f14fa37f8
@ -42,26 +42,16 @@ public bool HasSpace(int numBytes)
|
|||||||
public bool SendToTransport(NetworkConnection conn, int channelId)
|
public bool SendToTransport(NetworkConnection conn, int channelId)
|
||||||
{
|
{
|
||||||
byte error;
|
byte error;
|
||||||
|
if (conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out error))
|
||||||
bool result = true;
|
|
||||||
if (!conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out error))
|
|
||||||
{
|
{
|
||||||
if (m_IsReliable && error == (int)NetworkError.NoResources)
|
m_Position = 0;
|
||||||
{
|
return true;
|
||||||
// handled below
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (LogFilter.logError) { Debug.LogError("Failed to send internal buffer channel:" + channelId + " bytesToSend:" + m_Position); }
|
// NoResources and reliable? Then it will be resent, so don't reset position, just return false.
|
||||||
result = false;
|
if (error == (int)NetworkError.NoResources && m_IsReliable)
|
||||||
}
|
|
||||||
}
|
|
||||||
if (error != 0)
|
|
||||||
{
|
{
|
||||||
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
|
#if UNITY_EDITOR
|
||||||
UnityEditor.NetworkDetailStats.IncrementStat(
|
UnityEditor.NetworkDetailStats.IncrementStat(
|
||||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||||
@ -70,11 +60,11 @@ public bool SendToTransport(NetworkConnection conn, int channelId)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogFilter.logError) { Debug.LogError("Send Error: " + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + m_Position); }
|
// otherwise something unexpected happened. log the error, reset position and return.
|
||||||
result = false;
|
if (LogFilter.logError) { Debug.LogError("SendToTransport failed. error:" + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + m_Position); }
|
||||||
}
|
|
||||||
m_Position = 0;
|
m_Position = 0;
|
||||||
return result;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user