usedPort := map[string]bool{}
nextPort := func() string {
for {
- port, err := availablePort(super.ListenHost + ":0")
+ port, err := availablePort(super.ListenHost)
if err != nil {
panic(err)
}
h = super.ListenHost
}
if p == "0" {
- p, err = availablePort(":0")
+ p, err = availablePort(h)
if err != nil {
return err
}
}
}
-func availablePort(addr string) (string, error) {
- ln, err := net.Listen("tcp", addr)
+func availablePort(host string) (string, error) {
+ ln, err := net.Listen("tcp", net.JoinHostPort(host, "0"))
if err != nil {
return "", err
}