]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Stabilize everything
authorForest <chocozilla@gmail.com>
Sun, 16 Dec 2018 20:01:06 +0000 (12:01 -0800)
committerForest <chocozilla@gmail.com>
Sun, 16 Dec 2018 20:01:06 +0000 (12:01 -0800)
Hazel/ObjectPool.cs
Hazel/Udp/UdpConnection.Reliable.cs

index c497b3b4ab682a3dad3e78ede48e890a5e1de8d1..fdc1058328b233feb7f31742a48e6cb694b1a586 100644 (file)
@@ -1,11 +1,8 @@
 using System;
-#if NET_45
 using System.Collections.Concurrent;
-#else
-using System.Collections.Generic;
-#endif
 using System.Linq;
 using System.Text;
+using System.Threading;
 
 namespace Hazel
 {
@@ -16,16 +13,15 @@ namespace Hazel
     /// <threadsafety static="true" instance="true"/>
     public sealed class ObjectPool<T> where T : IRecyclable
     {
+        private int numberCreated;
+        public int NumberCreated { get { return numberCreated; } }
+
         public int Size { get { return this.pool.Count; } }
 
         /// <summary>
         ///     Our pool of objects
         /// </summary>
-#if NET_45
         ConcurrentBag<T> pool = new ConcurrentBag<T>();
-#else
-        Queue<T> pool = new Queue<T>();
-#endif
 
         /// <summary>
         ///     The generator for creating new objects.
@@ -47,17 +43,11 @@ namespace Hazel
         /// <returns>An instance of T.</returns>
         internal T GetObject()
         {
-#if NET_45
             T item;
             if (pool.TryTake(out item))
                 return item;
-#else
-            lock (pool)
-            {
-                if (pool.Count > 0)
-                    return pool.Dequeue();
-            }
-#endif
+
+            Interlocked.Increment(ref numberCreated);
             return objectFactory.Invoke();
         }
 
@@ -67,12 +57,7 @@ namespace Hazel
         /// <param name="item">The item to return.</param>
         internal void PutObject(T item)
         {
-#if NET_45
             pool.Add(item);
-#else
-            lock (pool)
-                pool.Enqueue(item);
-#endif
         }
     }
 }
index 7f802ec4c31ba08d99ec38bd60dbdc936357d3f0..6314f5fd8134edf5f792f9cce31dc6c01b242e0a 100644 (file)
@@ -101,7 +101,7 @@ namespace Hazel.Udp
             public volatile bool Acknowledged;
             public volatile int Retransmissions;
             public Stopwatch Stopwatch = new Stopwatch();
-
+            
             Packet()
             {
 
@@ -189,10 +189,6 @@ namespace Hazel.Udp
                         {
                             if (!p.Acknowledged)
                             {
-                                // Backoff retry frequency to avoid congestion
-                                p.LastTimeout = (int)Math.Min(p.LastTimeout * 1.5f, this.disconnectTimeout / 2f);
-                                p.Timer.Change(p.LastTimeout, Timeout.Infinite);
-
                                 if (p.Stopwatch.ElapsedMilliseconds > this.disconnectTimeout)
                                 {
                                     HandleDisconnect(new HazelException($"Reliable packet {id} was not ack'd after {p.Retransmissions} resends"));
@@ -203,6 +199,10 @@ namespace Hazel.Udp
                                     p.Recycle();
                                     return;
                                 }
+
+                                // Backoff retry frequency to avoid congestion
+                                p.LastTimeout = (int)Math.Min(p.LastTimeout * 1.5f, this.disconnectTimeout / 2f);
+                                p.Timer.Change(p.LastTimeout, Timeout.Infinite);
                             }
                         }
 
@@ -438,10 +438,10 @@ namespace Hazel.Udp
         {
             lock (this.reliableDataPacketsSent)
             {
-                var packets = this.reliableDataPacketsSent.Keys.ToArray();
                 foreach (var kvp in this.reliableDataPacketsSent)
                 {
                     Packet pkt = kvp.Value;
+                    pkt.Acknowledged = true;
                     pkt.Recycle();
                 }