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

@ -0,0 +1,22 @@
//go:build !go1.20
package dialer
import (
"context"
"net"
"syscall"
)
func addControlToDialer(d *net.Dialer, fn controlFn) {
ld := *d
d.Control = func(network, address string, c syscall.RawConn) (err error) {
switch {
case ld.Control != nil:
if err = ld.Control(network, address, c); err != nil {
return
}
}
return fn(context.Background(), network, address, c)
}
}