mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-16 06:01:21 +08:00
25 lines
466 B
Go
25 lines
466 B
Go
|
package dialer
|
||
|
|
||
|
import (
|
||
|
"net"
|
||
|
"syscall"
|
||
|
|
||
|
"golang.org/x/sys/windows"
|
||
|
)
|
||
|
|
||
|
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) {
|
||
|
windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
|
||
|
})
|
||
|
}
|
||
|
}
|