2021-09-06 23:07:34 +08:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
|
|
|
|
|
|
|
package dialer
|
|
|
|
|
|
|
|
import (
|
2023-02-13 11:14:19 +08:00
|
|
|
"context"
|
2021-09-06 23:07:34 +08:00
|
|
|
"net"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func addrReuseToListenConfig(lc *net.ListenConfig) {
|
2023-02-13 11:14:19 +08:00
|
|
|
addControlToListenConfig(lc, func(ctx context.Context, network, address string, c syscall.RawConn) error {
|
2021-09-06 23:07:34 +08: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 11:14:19 +08:00
|
|
|
})
|
2021-09-06 23:07:34 +08:00
|
|
|
}
|