summaryrefslogtreecommitdiffhomepage
path: root/conn
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2021-03-29 13:21:06 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2021-03-30 12:09:38 -0700
commit204140016af494ef8e0dd2749d4ae6c4a0828a9e (patch)
tree6688e737130653862f205bc80bd3d3539224ff5c /conn
parent822f5a6d70c22df93ed1680fbe14ef3733647e89 (diff)
conn: use local ipvN vars in StdNetBind.Open
This makes it clearer that they are fresh on each attempt, and avoids the bookkeeping required to clearing them on failure. Also, remove an unnecessary err != nil. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
Diffstat (limited to 'conn')
-rw-r--r--conn/bind_std.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/conn/bind_std.go b/conn/bind_std.go
index 73946b4..a511341 100644
--- a/conn/bind_std.go
+++ b/conn/bind_std.go
@@ -91,30 +91,28 @@ func (bind *StdNetBind) Open(uport uint16) (uint16, error) {
again:
port := int(uport)
+ var ipv4, ipv6 *net.UDPConn
- bind.ipv4, port, err = listenNet("udp4", port)
+ ipv4, port, err = listenNet("udp4", port)
if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
- bind.ipv4 = nil
return 0, err
}
- bind.ipv6, port, err = listenNet("udp6", port)
- if uport == 0 && err != nil && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
- bind.ipv4.Close()
- bind.ipv4 = nil
- bind.ipv6 = nil
+ ipv6, port, err = listenNet("udp6", port)
+ if uport == 0 && errors.Is(err, syscall.EADDRINUSE) && tries < 100 {
+ ipv4.Close()
tries++
goto again
}
if err != nil && !errors.Is(err, syscall.EAFNOSUPPORT) {
- bind.ipv4.Close()
- bind.ipv4 = nil
- bind.ipv6 = nil
+ ipv4.Close()
return 0, err
}
- if bind.ipv4 == nil && bind.ipv6 == nil {
+ if ipv4 == nil && ipv6 == nil {
return 0, syscall.EAFNOSUPPORT
}
+ bind.ipv4 = ipv4
+ bind.ipv6 = ipv6
return uint16(port), nil
}