chore: better windows bind error handle
This commit is contained in:
parent
baaf509637
commit
5c8d955f61
1 changed files with 18 additions and 7 deletions
|
@ -37,14 +37,25 @@ func bindControl(ifaceIdx int) controlFn {
|
||||||
var innerErr error
|
var innerErr error
|
||||||
err = c.Control(func(fd uintptr) {
|
err = c.Control(func(fd uintptr) {
|
||||||
handle := syscall.Handle(fd)
|
handle := syscall.Handle(fd)
|
||||||
|
bind6err := bind6(handle, ifaceIdx)
|
||||||
|
bind4err := bind4(handle, ifaceIdx)
|
||||||
switch network {
|
switch network {
|
||||||
case "tcp6", "udp6":
|
case "ip6", "tcp6":
|
||||||
innerErr = bind6(handle, ifaceIdx)
|
innerErr = bind6err
|
||||||
_ = bind4(handle, ifaceIdx)
|
case "ip4", "tcp4", "udp4":
|
||||||
default:
|
innerErr = bind4err
|
||||||
innerErr = bind4(handle, ifaceIdx)
|
case "udp6":
|
||||||
// try bind ipv6, if failed, ignore. it's a workaround for windows disable interface ipv6
|
// golang will set network to udp6 when listenUDP on wildcard ip (eg: ":0", "")
|
||||||
_ = bind6(handle, ifaceIdx)
|
if (!addrPort.Addr().IsValid() || addrPort.Addr().IsUnspecified()) && bind6err != nil {
|
||||||
|
// try bind ipv6, if failed, ignore. it's a workaround for windows disable interface ipv6
|
||||||
|
if bind4err != nil {
|
||||||
|
innerErr = bind6err
|
||||||
|
} else {
|
||||||
|
innerErr = bind4err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
innerErr = bind6err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue