This commit is contained in:
2026-05-28 21:32:46 +02:00
parent e8cac569e3
commit e82e30dd02
29 changed files with 2485 additions and 97 deletions
+18
View File
@@ -0,0 +1,18 @@
//go:build !windows
package udp
import "golang.org/x/sys/unix"
// setSocketReuse enables SO_REUSEADDR + SO_REUSEPORT on Linux/macOS so
// multiple processes can share a multicast UDP port (matches the Windows
// behaviour with SO_REUSEADDR).
func setSocketReuse(fd uintptr) error {
if err := unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1); err != nil {
return err
}
// SO_REUSEPORT isn't defined on every Unix; the syscall returning
// ENOPROTOOPT is fine to ignore.
_ = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
return nil
}