//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
}
