Fix rebind to not put the socket in blocking mode (#972)

This commit is contained in:
Nate Brown 2023-09-07 11:56:09 -05:00 committed by GitHub
parent d271df8da8
commit f7e392995a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -43,10 +43,15 @@ func NewListenConfig(multi bool) net.ListenConfig {
}
func (u *GenericConn) Rebind() error {
file, err := u.File()
rc, err := u.UDPConn.SyscallConn()
if err != nil {
return err
}
return syscall.SetsockoptInt(int(file.Fd()), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, 0)
return rc.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, 0)
if err != nil {
u.l.WithError(err).Error("Failed to rebind udp socket")
}
})
}