summaryrefslogtreecommitdiff
path: root/Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-01-24 16:59:24 +0800
committerchai <chaifix@163.com>2022-01-24 16:59:24 +0800
commit82dfb967df39b14597a34ce9a7c39fda60c251ad (patch)
tree6e9a671716813d49939bde224f73ed1c5d75832d /Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs
+init
Diffstat (limited to 'Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs')
-rw-r--r--Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs b/Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs
new file mode 100644
index 0000000..1a1ffa1
--- /dev/null
+++ b/Playground/Assets/ConsolePro/Remote/LiteNetLib/SimpleChannel.cs
@@ -0,0 +1,40 @@
+#if DEBUG && !UNITY_WP_8_1 && !UNITY_WSA
+using System.Collections.Generic;
+
+namespace FlyingWormConsole3.LiteNetLib
+{
+ internal sealed class SimpleChannel
+ {
+ private readonly Queue<NetPacket> _outgoingPackets;
+ private readonly NetPeer _peer;
+
+ public SimpleChannel(NetPeer peer)
+ {
+ _outgoingPackets = new Queue<NetPacket>();
+ _peer = peer;
+ }
+
+ public void AddToQueue(NetPacket packet)
+ {
+ lock (_outgoingPackets)
+ {
+ _outgoingPackets.Enqueue(packet);
+ }
+ }
+
+ public bool SendNextPacket()
+ {
+ NetPacket packet;
+ lock (_outgoingPackets)
+ {
+ if (_outgoingPackets.Count == 0)
+ return false;
+ packet = _outgoingPackets.Dequeue();
+ }
+ _peer.SendRawData(packet);
+ _peer.Recycle(packet);
+ return true;
+ }
+ }
+}
+#endif