From a1e4aed2dcf92a0b41c61438961f8cdb7f8d0b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Thu, 29 Jul 2021 14:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E6=9D=9F=E8=BF=9B=E7=A8=8B=E5=B9=B6?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E7=BB=93=E6=9D=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.Dns/DnsServer.cs | 18 +----------------- FastGithub.Dns/UdpTable.cs | 4 +++- FastGithub.ReverseProxy/TcpTable.cs | 4 +++- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/FastGithub.Dns/DnsServer.cs b/FastGithub.Dns/DnsServer.cs index 9ab0a1d..f2489b0 100644 --- a/FastGithub.Dns/DnsServer.cs +++ b/FastGithub.Dns/DnsServer.cs @@ -59,23 +59,7 @@ namespace FastGithub.Dns this.socket.IOControl(SIO_UDP_CONNRESET, new byte[4], new byte[4]); } this.socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - - var maxSpinCount = 100; - var spinWait = new SpinWait(); - var localEndPoint = new IPEndPoint(address, port); - - for (var i = 0; i < maxSpinCount; i++) - { - try - { - this.socket.Bind(localEndPoint); - break; - } - catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AccessDenied) - { - spinWait.SpinOnce(); - } - } + this.socket.Bind(new IPEndPoint(address, port)); } /// diff --git a/FastGithub.Dns/UdpTable.cs b/FastGithub.Dns/UdpTable.cs index f126fdc..3a5eb9b 100644 --- a/FastGithub.Dns/UdpTable.cs +++ b/FastGithub.Dns/UdpTable.cs @@ -34,7 +34,9 @@ namespace FastGithub.Dns try { - Process.GetProcessById(pid).Kill(); + var proess = Process.GetProcessById(pid); + proess.Kill(); + proess.WaitForExit(); return true; } catch (ArgumentException) diff --git a/FastGithub.ReverseProxy/TcpTable.cs b/FastGithub.ReverseProxy/TcpTable.cs index 4e8065d..47c7dea 100644 --- a/FastGithub.ReverseProxy/TcpTable.cs +++ b/FastGithub.ReverseProxy/TcpTable.cs @@ -34,7 +34,9 @@ namespace FastGithub.ReverseProxy try { - Process.GetProcessById(pid).Kill(); + var proess = Process.GetProcessById(pid); + proess.Kill(); + proess.WaitForExit(); return true; } catch (ArgumentException)