📄 ingoinglist.cs
字号:
namespace NCindy.Protocol.RUDP.Packet
{
using System;
using System.Collections.Generic;
internal sealed class IngoingList
{
private int _biggestPacketId = -1;
private int _currentPacketId = -1;
private readonly LinkedList<RUDPIngoingPacket> _list = new LinkedList<RUDPIngoingPacket>();
private readonly object _lock = new object();
internal void AddPacket(RUDPIngoingPacket packet)
{
lock (this._lock)
{
this._biggestPacketId = Math.Max(this._biggestPacketId, packet.PacketId);
if (packet.PacketId < 0)
{
this._list.AddLast(packet);
}
else
{
LinkedListNode<RUDPIngoingPacket> node = this._list.get_Last();
LinkedListNode<RUDPIngoingPacket> node2 = null;
while ((node != null) && ((node.get_Value().PacketId < 0) || (packet.PacketId < node.get_Value().PacketId)))
{
if ((node2 == null) && (node.get_Value().PacketId < 0))
{
node2 = node;
}
node = node.get_Previous();
if ((node != null) && (packet.PacketId < node.get_Value().PacketId))
{
node2 = null;
}
}
if (node2 != null)
{
this._list.AddAfter(node2, packet);
}
else if (node == null)
{
this._list.AddFirst(packet);
}
else if (packet.PacketId != node.get_Value().PacketId)
{
this._list.AddAfter(node, packet);
}
}
}
}
internal void Clear()
{
lock (this._lock)
{
this._list.Clear();
this._currentPacketId = -1;
this._biggestPacketId = -1;
}
}
internal bool ContainsPacket(int packetId)
{
lock (this._lock)
{
LinkedListNode<RUDPIngoingPacket> node = this._list.get_First();
while (node != null)
{
if (node.get_Value().PacketId != packetId)
{
node = node.get_Next();
}
else
{
return true;
}
}
}
return false;
}
internal RUDPIngoingPacket RemoveNextPacket()
{
lock (this._lock)
{
LinkedListNode<RUDPIngoingPacket> node = this._list.get_First();
if (node == null)
{
return null;
}
if ((node.get_Value().PacketId <= -1) || (node.get_Value().PacketId != (this._currentPacketId + 1)))
{
goto Label_0090;
}
this._currentPacketId++;
this._list.Remove(node);
return node.get_Value();
Label_0066:
if (node.get_Value().PacketId < 0)
{
this._list.Remove(node);
return node.get_Value();
}
node = node.get_Next();
Label_0090:
if (node != null)
{
goto Label_0066;
}
}
return null;
}
internal int BiggestPacketId
{
get
{
return this._biggestPacketId;
}
}
internal int Count
{
get
{
return this._list.get_Count();
}
}
internal int CurrentPacketId
{
get
{
return this._currentPacketId;
}
set
{
this._currentPacketId = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -