mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net: make newLocalListener handle network argument correcly
Change-Id: I8987e705af069846e6668e2f2104e0254e695139 Reviewed-on: https://go-review.googlesource.com/19706 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
9194421eed
commit
6716a54e36
1 changed files with 11 additions and 1 deletions
|
|
@ -30,10 +30,20 @@ func testUnixAddr() string {
|
|||
|
||||
func newLocalListener(network string) (Listener, error) {
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
case "tcp":
|
||||
if supportsIPv4 {
|
||||
if ln, err := Listen("tcp4", "127.0.0.1:0"); err == nil {
|
||||
return ln, nil
|
||||
}
|
||||
}
|
||||
if supportsIPv6 {
|
||||
return Listen("tcp6", "[::1]:0")
|
||||
}
|
||||
case "tcp4":
|
||||
if supportsIPv4 {
|
||||
return Listen("tcp4", "127.0.0.1:0")
|
||||
}
|
||||
case "tcp6":
|
||||
if supportsIPv6 {
|
||||
return Listen("tcp6", "[::1]:0")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue