mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
394 B
17 lines
394 B
7 years ago
|
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)
|
||
|
}
|