陈国伟 преди 3 години
родител
ревизия
f67fe2e46f
променени са 2 файла, в които са добавени 14 реда и са изтрити 4 реда
  1. 7 2
      FastGithub.PacketIntercept/Dns/DnsInterceptor.cs
  2. 7 2
      FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs

+ 7 - 2
FastGithub.PacketIntercept/Dns/DnsInterceptor.cs

@@ -23,6 +23,7 @@ namespace FastGithub.PacketIntercept.Dns
     [SupportedOSPlatform("windows")]
     sealed class DnsInterceptor : IDnsInterceptor
     {
+        private const int ERROR_INVALID_HANDLE = 0x6;
         private const string DNS_FILTER = "udp.DstPort == 53";
         private readonly FastGithubConfig fastGithubConfig;
         private readonly ILogger<DnsInterceptor> logger;
@@ -97,8 +98,12 @@ namespace FastGithub.PacketIntercept.Dns
                 }
                 else
                 {
-                    var exception = new Win32Exception(Marshal.GetLastWin32Error());
-                    this.logger.LogError(exception.Message);
+                    var errorCode = Marshal.GetLastWin32Error();
+                    this.logger.LogError(new Win32Exception(errorCode).Message);
+                    if (errorCode == ERROR_INVALID_HANDLE)
+                    {
+                        break;
+                    }
                 }
             }
         }

+ 7 - 2
FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs

@@ -17,6 +17,7 @@ namespace FastGithub.PacketIntercept.Tcp
     [SupportedOSPlatform("windows")]
     abstract class TcpInterceptor : ITcpInterceptor
     {
+        private const int ERROR_INVALID_HANDLE = 0x6;
         private readonly string filter;
         private readonly ushort oldServerPort;
         private readonly ushort newServerPort;
@@ -82,8 +83,12 @@ namespace FastGithub.PacketIntercept.Tcp
                 }
                 else
                 {
-                    var exception = new Win32Exception(Marshal.GetLastWin32Error());
-                    this.logger.LogError(exception.Message);
+                    var errorCode = Marshal.GetLastWin32Error();
+                    this.logger.LogError(new Win32Exception(errorCode).Message);
+                    if (errorCode == ERROR_INVALID_HANDLE)
+                    {
+                        break;
+                    }
                 }
             }
         }