mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-02 18:14:01 +00:00
26 lines
522 B
Go
26 lines
522 B
Go
//go:build go1.20
|
|
|
|
package dialer
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"syscall"
|
|
)
|
|
|
|
func addControlToDialer(d *net.Dialer, fn controlFn) {
|
|
ld := *d
|
|
d.ControlContext = func(ctx context.Context, network, address string, c syscall.RawConn) (err error) {
|
|
switch {
|
|
case ld.ControlContext != nil:
|
|
if err = ld.ControlContext(ctx, network, address, c); err != nil {
|
|
return
|
|
}
|
|
case ld.Control != nil:
|
|
if err = ld.Control(network, address, c); err != nil {
|
|
return
|
|
}
|
|
}
|
|
return fn(ctx, network, address, c)
|
|
}
|
|
}
|