mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Fix #589 GetProcessByUsedTcpPort multiple process
This commit is contained in:
@@ -191,8 +191,7 @@ namespace Netch.Controllers
|
||||
|
||||
public static void TryReleaseTcpPort(ushort port, string portName)
|
||||
{
|
||||
Process? p;
|
||||
if ((p = PortHelper.GetProcessByUsedTcpPort(port)) != null)
|
||||
foreach (var p in PortHelper.GetProcessByUsedTcpPort(port))
|
||||
{
|
||||
if (p.MainModule!.FileName.StartsWith(Global.NetchDir))
|
||||
{
|
||||
|
||||
@@ -28,16 +28,14 @@ namespace Netch.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static Process? GetProcessByUsedTcpPort(ushort port)
|
||||
public static IEnumerable<Process> GetProcessByUsedTcpPort(ushort port)
|
||||
{
|
||||
if (port == 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
var row = GetTcpTable2().SingleOrDefault(r => ntohs((ushort) r.dwLocalPort) == port);
|
||||
if (row.dwOwningPid == 0)
|
||||
return null;
|
||||
var row = GetTcpTable2().Where(r => ntohs((ushort) r.dwLocalPort) == port);
|
||||
|
||||
return Process.GetProcessById((int) row.dwOwningPid);
|
||||
return row.Select(r => Process.GetProcessById((int) r.dwOwningPid));
|
||||
}
|
||||
|
||||
private static void GetReservedPortRange(PortType portType, ref List<Range> targetList)
|
||||
|
||||
Reference in New Issue
Block a user