2021-09-06 15:07:34 +00:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
|
|
|
|
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
2023-02-13 03:14:19 +00:00
|
|
|
"context"
|
2021-09-06 15:07:34 +00:00
|
|
|
"net"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func addrReuseToListenConfig(lc *net.ListenConfig) {
|
2023-02-13 03:14:19 +00:00
|
|
|
addControlToListenConfig(lc, func(ctx context.Context, network, address string, c syscall.RawConn) error {
|
2021-09-06 15:07:34 +00:00
|
|
|
return c.Control(func(fd uintptr) {
|
|
|
|
unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
|
|
|
|
unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
|
|
|
})
|
2023-02-13 03:14:19 +00:00
|
|
|
})
|
2021-09-06 15:07:34 +00:00
|
|
|
}
|