Update IPCSocket.vb

master
xieguigang 4 years ago
parent 3cbab813cc
commit 384e9386ed

@ -109,32 +109,36 @@ Public Class IPCSocket : Implements ITaskDriver
Public Shared Function GetFirstAvailablePort() As Integer
Call Thread.Sleep(randf.NextInteger(1000))
If Environment.OSVersion.Platform = PlatformID.Unix Then
#If netcore5 = 1 Then
If Not "/bin/bash".FileExists Then
Return TCPExtensions.GetFirstAvailablePort(-1)
End If
' 使
Dim BEGIN_PORT = randf.NextInteger(MAX_PORT - 1)
Dim stdout As String = CommandLine.Call("/bin/bash", "-c ""netstat -tulpn""")
Dim usedPorts As Index(Of Integer) = stdout.LineTokens _
.Select(Function(line) line.StringSplit("\s+").ElementAt(3)) _
.Where(Function(n) n.IsPattern(".+[:]\d+")) _
.Select(Function(i) Integer.Parse(i.Split(":"c).Last)) _
.Indexing
For i As Integer = BEGIN_PORT To MAX_PORT - 1
If Not i Like usedPorts Then
Return i
If Not "/bin/bash".FileExists Then
Return TCPExtensions.GetFirstAvailablePort(-1)
End If
Next
Return -1
' 使
Dim BEGIN_PORT = randf.NextInteger(MAX_PORT - 1)
Dim stdout As String = CommandLine.Call("/bin/bash", "-c ""netstat -tulpn""")
Dim usedPorts As Index(Of Integer) = stdout.LineTokens _
.Select(Function(line) line.StringSplit("\s+").ElementAt(3)) _
.Where(Function(n) n.IsPattern(".+[:]\d+")) _
.Select(Function(i) Integer.Parse(i.Split(":"c).Last)) _
.Indexing
For i As Integer = BEGIN_PORT To MAX_PORT - 1
If Not i Like usedPorts Then
Return i
End If
Next
Return -1
#Else
' PlatformNotSupportedException: The information requested is unavailable on the current platform.
' on UNIX .net 5
Return TCPExtensions.GetFirstAvailablePort(-1)
#End If
Else
Return TCPExtensions.GetFirstAvailablePort(-1)
End If
End Function
Public Function GetLastError() As String

Loading…
Cancel
Save