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