mirror of
https://github.com/Kaveinator/NetickProForUnity.git
synced 2025-10-26 17:59:07 -07:00
auto
This commit is contained in:
48
Transport/LiteNetLib Transport/LiteNetLib/BaseChannel.cs
Normal file
48
Transport/LiteNetLib Transport/LiteNetLib/BaseChannel.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace LiteNetLib
|
||||
{
|
||||
internal abstract class BaseChannel
|
||||
{
|
||||
protected readonly NetPeer Peer;
|
||||
protected readonly Queue<NetPacket> OutgoingQueue = new Queue<NetPacket>(NetConstants.DefaultWindowSize);
|
||||
private int _isAddedToPeerChannelSendQueue;
|
||||
|
||||
public int PacketsInQueue => OutgoingQueue.Count;
|
||||
|
||||
protected BaseChannel(NetPeer peer)
|
||||
{
|
||||
Peer = peer;
|
||||
}
|
||||
|
||||
public void AddToQueue(NetPacket packet)
|
||||
{
|
||||
lock (OutgoingQueue)
|
||||
{
|
||||
OutgoingQueue.Enqueue(packet);
|
||||
}
|
||||
AddToPeerChannelSendQueue();
|
||||
}
|
||||
|
||||
protected void AddToPeerChannelSendQueue()
|
||||
{
|
||||
if (Interlocked.CompareExchange(ref _isAddedToPeerChannelSendQueue, 1, 0) == 0)
|
||||
{
|
||||
Peer.AddToReliableChannelSendQueue(this);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SendAndCheckQueue()
|
||||
{
|
||||
bool hasPacketsToSend = SendNextPackets();
|
||||
if (!hasPacketsToSend)
|
||||
Interlocked.Exchange(ref _isAddedToPeerChannelSendQueue, 0);
|
||||
|
||||
return hasPacketsToSend;
|
||||
}
|
||||
|
||||
protected abstract bool SendNextPackets();
|
||||
public abstract bool ProcessPacket(NetPacket packet);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user