reuse_unix.go 517 B

1234567891011121314151617181920
  1. //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
  2. package dialer
  3. import (
  4. "context"
  5. "net"
  6. "syscall"
  7. "golang.org/x/sys/unix"
  8. )
  9. func addrReuseToListenConfig(lc *net.ListenConfig) {
  10. addControlToListenConfig(lc, func(ctx context.Context, network, address string, c syscall.RawConn) error {
  11. return c.Control(func(fd uintptr) {
  12. unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
  13. unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
  14. })
  15. })
  16. }