From: Forest Date: Thu, 3 Sep 2020 22:31:52 +0000 (-0700) Subject: Hazel pretty good. 2020.9.1 X-Git-Tag: 1.0.0~27^2~4 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=1eb467139c6b32234681c4b75e989387d3cc1242;p=rhonda%2Fimpostor.hazel.git Hazel pretty good. 2020.9.1 --- diff --git a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs index 87e8fbf..10076d7 100644 --- a/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs +++ b/Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs @@ -51,12 +51,12 @@ namespace Hazel.Udp.FewerThreads private ConcurrentDictionary allConnections = new ConcurrentDictionary(); - private Queue receiveQueue = new Queue(); + private BlockingCollection receiveQueue; private Queue sendQueue = new Queue(); public int ConnectionCount { get { return this.allConnections.Count; } } public int SendQueueLength { get { lock(this.sendQueue) return this.sendQueue.Count; } } - public int ReceiveQueueLength { get { lock (this.receiveQueue) return this.receiveQueue.Count; } } + public int ReceiveQueueLength { get { return this.receiveQueue.Count; } } private bool isActive; @@ -66,6 +66,8 @@ namespace Hazel.Udp.FewerThreads this.EndPoint = endPoint; this.IPMode = ipMode; + this.receiveQueue = new BlockingCollection(10000); + this.socket = UdpConnection.CreateSocket(this.IPMode); this.socket.Blocking = false; @@ -140,11 +142,7 @@ namespace Hazel.Udp.FewerThreads return; } - lock (this.receiveQueue) - { - this.receiveQueue.Enqueue(new ReceiveMessageInfo() { Message = message, Sender = remoteEP }); - Monitor.Pulse(this.receiveQueue); - } + this.receiveQueue.Add(new ReceiveMessageInfo() { Message = message, Sender = remoteEP }); } } } @@ -153,28 +151,15 @@ namespace Hazel.Udp.FewerThreads { while (this.isActive) { - ReceiveMessageInfo msg; - lock (this.receiveQueue) - { - if (this.receiveQueue.Count == 0) - { - Monitor.Wait(this.receiveQueue); - - if (this.receiveQueue.Count == 0) - { - continue; - } - } - - msg = this.receiveQueue.Dequeue(); - } - + ReceiveMessageInfo msg = this.receiveQueue.Take(); + try { this.ReadCallback(msg.Message, msg.Sender); } catch { + } } } @@ -306,7 +291,8 @@ namespace Hazel.Udp.FewerThreads this.isActive = false; lock (this.sendQueue) Monitor.PulseAll(this.sendQueue); - lock (this.receiveQueue) Monitor.PulseAll(this.receiveQueue); + + this.receiveQueue.CompleteAdding(); this.reliablePacketThread.Join(); this.sendThread.Join(); diff --git a/Hazel/Hazel.csproj b/Hazel/Hazel.csproj index f6b10e6..6ca0b0a 100644 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@ -31,7 +31,7 @@ portable true bin\Release\ - TRACE + TRACE;HAZEL_BAG prompt 4 diff --git a/Hazel/ObjectPool.cs b/Hazel/ObjectPool.cs index db3e3b4..510e55a 100644 --- a/Hazel/ObjectPool.cs +++ b/Hazel/ObjectPool.cs @@ -99,7 +99,9 @@ namespace Hazel } else { +#if DEBUG throw new Exception("Duplicate add " + typeof(T).Name); +#endif } } }