Skip to content

Commit

Permalink
fix: avoiding throw from ResendMessages when send queue is full
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Jan 7, 2025
1 parent 8bdb6c1 commit a14a6fc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Assets/Mirage/Runtime/SocketLayer/Connection/AckSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AckSystem : IDisposable

// temp list for resending when processing sentqueue
private readonly HashSet<ReliablePacket> _toResend = new HashSet<ReliablePacket>();
private readonly List<ReliablePacket> _resendRemoveList = new List<ReliablePacket>();
private readonly IRawConnection _connection;
private readonly ITime _time;
private readonly Pool<ByteBuffer> _bufferPool;
Expand Down Expand Up @@ -643,12 +644,35 @@ private void ReliableLost(ushort sequence, ReliablePacket reliablePacket)

private void ResendMessages()
{
if (_toResend.Count == 0)
return;

_resendRemoveList.Clear();

foreach (var reliable in _toResend)
{
// exit early if we can't send any more packets
if (_sentAckablePackets.Count >= _maxPacketsInSendBufferPerConnection)
break;

_metrics?.OnResend(reliable.Length);
SendReliablePacket(reliable);
_resendRemoveList.Add(reliable);
}

// if we sent all packets, we can just clear the set
// otherwise we need to remove the ones we did send
if (_resendRemoveList.Count == _toResend.Count)
{
_toResend.Clear();
}
else
{
foreach (var reliable in _resendRemoveList)
{
_toResend.Remove(reliable);
}
}
_toResend.Clear();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down

0 comments on commit a14a6fc

Please sign in to comment.