]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Interestingly, SelectRead doesn't always return when you shut down, so some platforms...
authorForest <chocozilla@gmail.com>
Wed, 25 Aug 2021 19:41:32 +0000 (12:41 -0700)
committerForest <chocozilla@gmail.com>
Wed, 25 Aug 2021 19:41:32 +0000 (12:41 -0700)
Hazel/FewerThreads/ThreadLimitedUdpConnectionListener.cs

index e604765921f683a2e873fda9c3ec5eb1e0aa376c..3053363fc54f8870769b1318a21ac90cde138b64 100644 (file)
@@ -211,8 +211,10 @@ namespace Hazel.Udp.FewerThreads
         {
             while (this.isActive)
             {
-                if (this.socket.Poll(Timeout.Infinite, SelectMode.SelectRead))
+                if (this.socket.Poll(1000, SelectMode.SelectRead))
                 {
+                    if (!isActive) break;
+
                     EndPoint remoteEP = new IPEndPoint(this.EndPoint.Address, this.EndPoint.Port);
                     MessageReader message = MessageReader.GetSized(BufferSize);
                     try
@@ -266,6 +268,11 @@ namespace Hazel.Udp.FewerThreads
                     {
                         this.socket.SendTo(msg.Span.GetUnderlyingArray(), msg.Span.Offset, msg.Span.Length, SocketFlags.None, msg.Recipient);
                     }
+                    else
+                    {
+                        this.Logger.WriteError("Socket is no longer able to send");
+                        break;
+                    }
                 }
                 catch (Exception e)
                 {
@@ -373,6 +380,7 @@ namespace Hazel.Udp.FewerThreads
 
             // Flush outgoing packets
             this.sendQueue?.CompleteAdding();
+
             if (wasActive)
             {
                 this.sendThread.Join();