]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Resolve an iOS bug due to setting buffers too large, standardize some socket shutdown...
authorForest <chocozilla@gmail.com>
Mon, 25 Mar 2019 21:41:04 +0000 (14:41 -0700)
committerForest <chocozilla@gmail.com>
Mon, 25 Mar 2019 21:41:04 +0000 (14:41 -0700)
Hazel/Udp/UdpBroadcastListener.cs
Hazel/Udp/UdpBroadcaster.cs
Hazel/Udp/UdpClientConnection.cs
Hazel/Udp/UdpConnection.KeepAlive.cs
Hazel/Udp/UdpConnection.Reliable.cs
Hazel/Udp/UdpConnectionListener.cs

index fb8c52ab8daf7d39231ce538d1eacc3e8a5a2856..5ac1a17a7e7351e37a65848b12eb49374736160a 100644 (file)
@@ -139,21 +139,9 @@ namespace Hazel.Udp
         {
             if (this.socket != null)
             {
-                try
-                {
-                    this.socket.Shutdown(SocketShutdown.Both);
-                }
-                catch { }
-                try
-                {
-                    this.socket.Close();
-                }
-                catch { }
-                try
-                {
-                    this.socket.Dispose();
-                }
-                catch { }
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
                 this.socket = null;
             }
         }
index d0a9f8454cdf1f1957856e493aa09e775fb6d490..50c3c680250cdf19d4d092793be4c8051592eea9 100644 (file)
@@ -52,21 +52,9 @@ namespace Hazel.Udp
         {
             if (this.socket != null)
             {
-                try
-                {
-                    this.socket.Shutdown(SocketShutdown.Both);
-                }
-                catch { }
-                try
-                {
-                    this.socket.Close();
-                }
-                catch { }
-                try
-                {
-                    this.socket.Dispose();
-                }
-                catch { }
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
                 this.socket = null;
             }
         }
index 58a16be6f841919bb7ddc14605afb404a7b9c0f8..7ce5dbc23d1c6cd3976fb0298ec64325406b9e7d 100644 (file)
@@ -306,8 +306,10 @@ namespace Hazel.Udp
 
             if (this.socket != null)
             {
-                this.socket.Close();
-                this.socket.Dispose();
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
+
                 this.socket = null;
             }
 
index 67abe78eead4d7c514178cb004a1d266c2ecb26b..eccfc9861df46961e998d4ac11ec4c15f562609b 100644 (file)
@@ -38,7 +38,7 @@ namespace Hazel.Udp
                 ResetKeepAliveTimer();
             }
         }
-        int keepAliveInterval = 3000;
+        int keepAliveInterval = 2000;
 
         /// <summary>
         ///     The timer creating keepalive pulses.
index acac1bbfa05d36db1d1debb183cb2403ccff577c..af8251e24dbe9b86e4bfefc22f5a6f13b557b99c 100644 (file)
@@ -36,7 +36,7 @@ namespace Hazel.Udp
         /// A compounding multiplier to back off resend timeout.
         /// Applied to ping before first timeout when ResendTimeout == 0.
         /// </summary>
-        public volatile float ResendPingMultiplier = 3;
+        public volatile float ResendPingMultiplier = 2;
 
         /// <summary>
         ///     Holds the last ID allocated.
@@ -72,7 +72,7 @@ namespace Hazel.Udp
         ///     This returns the average ping for a one-way trip as calculated from the reliable packets that have been sent 
         ///     and acknowledged by the endpoint.
         /// </remarks>
-        public float AveragePingMs = 500;
+        public float AveragePingMs = 200;
 
         /// <summary>
         ///     The maximum times a message should be resent before marking the endpoint as disconnected.
@@ -171,7 +171,7 @@ namespace Hazel.Udp
                             return 0;
                         }
 
-                        this.NextTimeout = (int)Math.Min(this.NextTimeout * connection.ResendPingMultiplier, connection.DisconnectTimeout);
+                        this.NextTimeout = (int)Math.Min(this.NextTimeout * connection.ResendPingMultiplier, 1500);
                         try
                         {
                             connection.WriteBytesToConnection(this.Data, this.Length);
@@ -243,7 +243,7 @@ namespace Hazel.Udp
                 this,
                 buffer,
                 sendLength,
-                ResendTimeout > 0 ? ResendTimeout : (int)Math.Max(300, Math.Min(AveragePingMs * this.ResendPingMultiplier, 2000)),
+                ResendTimeout > 0 ? ResendTimeout : ClampToInt(AveragePingMs * this.ResendPingMultiplier, 300, 1000),
                 ackCallback);
 
             if (!reliableDataPacketsSent.TryAdd(id, packet))
@@ -252,6 +252,13 @@ namespace Hazel.Udp
             }
         }
 
+        public static int ClampToInt(float value, int min, int max)
+        {
+            if (value < min) return min;
+            if (value > max) return max;
+            return (int)value;
+        }
+
         /// <summary>
         ///     Sends the bytes reliably and stores the send.
         /// </summary>
index b38530da210f852ced7b9bc3d9facd06e7ab91dc..c137776e3aad4cf8fd5d77f3f99cf5b2b4437a79 100644 (file)
@@ -57,8 +57,8 @@ namespace Hazel.Udp
                 this.socket.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, false);
             }
 
-            socket.ReceiveBufferSize = 4194304;
-            socket.SendBufferSize = 1048576;
+            socket.ReceiveBufferSize = BufferSize;
+            socket.SendBufferSize = BufferSize;
             
             reliablePacketTimer = new Timer(ManageReliablePackets, null, 100, Timeout.Infinite);
         }
@@ -330,13 +330,9 @@ namespace Hazel.Udp
 
             if (this.socket != null)
             {
-                try
-                {
-                    this.socket.Shutdown(SocketShutdown.Both);
-                }
-                catch { }
-                this.socket.Close();
-                this.socket.Dispose();
+                try { this.socket.Shutdown(SocketShutdown.Both); } catch { }
+                try { this.socket.Close(); } catch { }
+                try { this.socket.Dispose(); } catch { }
                 this.socket = null;
             }