Skip to content

Commit

Permalink
fix: disconnecting player if send buffer is full
Browse files Browse the repository at this point in the history
Full send buffer will throw, This will cause issues when sending to multiple clients if just one of their send buffers is full
  • Loading branch information
James-Frowen committed Jul 9, 2024
1 parent d722758 commit 3ea2d5d
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions Assets/Mirage/Runtime/NetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,29 @@ public void Send<T>(T message, Channel channelId = Channel.Reliable)
/// <param name="channelId"></param>
public void Send(ArraySegment<byte> segment, Channel channelId = Channel.Reliable)
{
if (_isDisconnected) { return; }
if (_isDisconnected)
return;

if (channelId == Channel.Reliable)
try
{
_connection.SendReliable(segment);
if (channelId == Channel.Reliable)
{
_connection.SendReliable(segment);
}
else
{
_connection.SendUnreliable(segment);
}
}
else
catch (BufferFullException e)
{
_connection.SendUnreliable(segment);
logger.LogError($"Disconnecting player because send buffer was full. {e}");
Disconnect();
}
catch (NoConnectionException e)
{
logger.LogError($"Inner connection was disconnected, but disconnected flag not yet. {e}");
Disconnect();
}
}

Expand All @@ -233,7 +247,21 @@ public void Send<T>(T message, INotifyCallBack callBacks)
var segment = writer.ToArraySegment();
NetworkDiagnostics.OnSend(message, segment.Count, 1);
if (logger.LogEnabled()) logger.Log($"Sending {typeof(T)} to {this} channel:Notify");
_connection.SendNotify(segment, callBacks);

try
{
_connection.SendNotify(segment, callBacks);
}
catch (BufferFullException e)
{
logger.LogError($"Disconnecting player because send buffer was full. {e}");
Disconnect();
}
catch (NoConnectionException e)
{
logger.LogError($"Inner connection was disconnected, but disconnected flag not yet. {e}");
Disconnect();
}
}
}

Expand Down

0 comments on commit 3ea2d5d

Please sign in to comment.