chore: support golang1.20's dialer.ControlContext

This commit is contained in:
wwqgtxx
2023-02-13 11:14:19 +08:00
parent ce8929d153
commit ae42d35184
9 changed files with 96 additions and 65 deletions

View File

@@ -1,6 +1,7 @@
package dialer
import (
"context"
"net"
"syscall"
@@ -8,17 +9,9 @@ import (
)
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)
}
}()
addControlToListenConfig(lc, func(ctx context.Context, network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
})
}
})
}