mirror of https://github.com/Dreamacro/clash.git
29 lines
661 B
Go
29 lines
661 B
Go
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
||
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||
|
|
||
|
package dialer
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"syscall"
|
||
|
|
||
|
"golang.org/x/sys/unix"
|
||
|
)
|
||
|
|
||
|
func addrReuseToListenConfig(lc *net.ListenConfig) {
|
||
|
chain := lc.Control
|
||
|
|
||
|
lc.Control = func(network, address string, c syscall.RawConn) (err error) {
|
||
|
defer func() {
|
||
|
if err == nil && chain != nil {
|
||
|
err = chain(network, address, c)
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
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)
|
||
|
})
|
||
|
}
|
||
|
}
|