From: Forest Date: Thu, 13 Jun 2019 23:07:35 +0000 (-0700) Subject: Improve debuggability, and maybe fix a case where the disconnect handler wasn't getti... X-Git-Tag: 1.0.0~43 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=dd2419485b67f32ef049c6df7c1027ccc24de4a0;p=rhonda%2Fimpostor.hazel.git Improve debuggability, and maybe fix a case where the disconnect handler wasn't getting called --- diff --git a/Hazel.UnitTests/UdpConnectionTests.cs b/Hazel.UnitTests/UdpConnectionTests.cs index 26352b5..d363a23 100644 --- a/Hazel.UnitTests/UdpConnectionTests.cs +++ b/Hazel.UnitTests/UdpConnectionTests.cs @@ -3,8 +3,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net; using System.Threading; using Hazel.Udp; -using System.Linq; -using System.Collections.Generic; namespace Hazel.UnitTests { @@ -66,7 +64,7 @@ namespace Hazel.UnitTests connection.Connect(); connection.Dispose(); - Thread.Sleep(10); + Thread.Sleep(50); Assert.IsTrue(serverConnected); Assert.IsTrue(serverDisconnected); diff --git a/Hazel/Hazel.csproj b/Hazel/Hazel.csproj index 6466a40..5114784 100644 --- a/Hazel/Hazel.csproj +++ b/Hazel/Hazel.csproj @@ -25,6 +25,7 @@ true false + 7.3 pdbonly @@ -37,6 +38,7 @@ true false + 7.3 true @@ -54,6 +56,7 @@ AnyCPU prompt MinimumRecommendedRules.ruleset + 7.3 diff --git a/Hazel/NetworkConnection.cs b/Hazel/NetworkConnection.cs index 0a224a8..c6426fc 100644 --- a/Hazel/NetworkConnection.cs +++ b/Hazel/NetworkConnection.cs @@ -40,18 +40,13 @@ namespace Hazel /// /// The exception if one was the cause. public override void Disconnect(string reason) - { - this.Disconnect(reason, false); - } - - protected void Disconnect(string reason, bool skipSendDisconnect) { bool invoke = false; lock (this) { if (this._state == ConnectionState.Connected) { - this._state = skipSendDisconnect ? ConnectionState.NotConnected : ConnectionState.Disconnecting; + this._state = ConnectionState.Disconnecting; invoke = true; } } diff --git a/Hazel/ObjectPool.cs b/Hazel/ObjectPool.cs index 1b48415..d508fba 100644 --- a/Hazel/ObjectPool.cs +++ b/Hazel/ObjectPool.cs @@ -1,7 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Linq; -using System.Text; using System.Threading; namespace Hazel @@ -54,7 +52,7 @@ namespace Hazel if (!inuse.TryAdd(item, true)) { - throw new Exception("Duplicate pull"); + throw new Exception("Duplicate pull " + typeof(T).Name); } return item; @@ -72,7 +70,7 @@ namespace Hazel } else { - throw new Exception("Duplicate add"); + throw new Exception("Duplicate add " + typeof(T).Name); } } } diff --git a/Hazel/Udp/UdpClientConnection.cs b/Hazel/Udp/UdpClientConnection.cs index 16b7d15..a09f830 100644 --- a/Hazel/Udp/UdpClientConnection.cs +++ b/Hazel/Udp/UdpClientConnection.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net; using System.Net.Sockets; -using System.Text; using System.Threading; @@ -100,7 +97,7 @@ namespace Hazel.Udp } catch (SocketException ex) { - Disconnect("Could not send data as a SocketException occured: " + ex.Message, true); + Disconnect("Could not send data as a SocketException occured: " + ex.Message); } } @@ -117,7 +114,7 @@ namespace Hazel.Udp } catch (SocketException ex) { - Disconnect("Could not send data as a SocketException occured: " + ex.Message, true); + Disconnect("Could not send data as a SocketException occured: " + ex.Message); } } diff --git a/Hazel/Udp/UdpConnection.cs b/Hazel/Udp/UdpConnection.cs index 051214e..c1e6cf4 100644 --- a/Hazel/Udp/UdpConnection.cs +++ b/Hazel/Udp/UdpConnection.cs @@ -128,7 +128,7 @@ namespace Hazel.Udp break; case (byte)UdpSendOption.Disconnect: - Disconnect("The remote sent a disconnect request", true); + Disconnect("The remote sent a disconnect request"); message.Recycle(); break; diff --git a/Hazel/Udp/UdpServerConnection.cs b/Hazel/Udp/UdpServerConnection.cs index fa15edb..1d01c76 100644 --- a/Hazel/Udp/UdpServerConnection.cs +++ b/Hazel/Udp/UdpServerConnection.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Net; -using System.Text; -using System.Threading; namespace Hazel.Udp {