From f7e392995ad2fec6d67c2a522e72b4d0848aa799 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Thu, 7 Sep 2023 11:56:09 -0500 Subject: [PATCH] Fix rebind to not put the socket in blocking mode (#972) --- udp/udp_darwin.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/udp/udp_darwin.go b/udp/udp_darwin.go index afbf240..08e1b6a 100644 --- a/udp/udp_darwin.go +++ b/udp/udp_darwin.go @@ -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") + } + }) }