mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-08-20 01:14:07 +00: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)
|
|
})
|
|
}
|
|
}
|