summaryrefslogtreecommitdiffhomepage
path: root/conn
diff options
context:
space:
mode:
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
}