1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-28 21:15:46 -05:00

move tcp.PickPort to its own package

This commit is contained in:
Darien Raymond
2018-03-01 11:53:39 +01:00
parent a7d467992d
commit af29e42771
14 changed files with 94 additions and 85 deletions

View File

@@ -0,0 +1,16 @@
package tcp
import (
"v2ray.com/core/common"
"v2ray.com/core/common/net"
)
// PickPort returns an unused TCP port in the system. The port returned is highly likely to be unused, but not guaranteed.
func PickPort() net.Port {
listener, err := net.Listen("tcp4", "127.0.0.1:0")
common.Must(err)
defer listener.Close()
addr := listener.Addr().(*net.TCPAddr)
return net.Port(addr.Port)
}