Skip to content

Commit

Permalink
Fix rebind to not put the socket in blocking mode (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrownus authored Sep 7, 2023
1 parent d271df8 commit f7e3929
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions udp/udp_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})
}

0 comments on commit f7e3929

Please sign in to comment.