|
|
|
|
@ -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
|
|
|
|
|
|