summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-03-29 13:27:21 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-03-30 12:09:38 -0700
commit517f0703f515f8cfad2f5887d71ca6fbfbbd4d72 (patch)
treec85bb8ffd3e7058f36dcee69607dc25448343fcd
parent204140016af494ef8e0dd2749d4ae6c4a0828a9e (diff)
conn: document retry loop in StdNetBind.Open
It's not obvious on a first read what the loop is doing. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
-rw-r--r--conn/bind_std.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/conn/bind_std.go b/conn/bind_std.go
index a511341..f8b8a1b 100644
--- a/conn/bind_std.go
+++ b/conn/bind_std.go
@@ -89,6 +89,8 @@ func (bind *StdNetBind) Open(uport uint16) (uint16, error) {
return 0, ErrBindAlreadyOpen
}
+ // Attempt to open ipv4 and ipv6 listeners on the same port.
+ // If uport is 0, we can retry on failure.
again:
port := int(uport)
var ipv4, ipv6 *net.UDPConn
@@ -98,6 +100,7 @@ again:
return 0, err
}
+ // Listen on the same port as we're using for ipv4.
ipv6, port, err = listenNet("udp6", port)
if uport == 0 && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
ipv4.Close()