mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-09-12 03:42:32 +00:00
23 lines
485 B
Go
23 lines
485 B
Go
|
package dialer
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"net"
|
||
|
"syscall"
|
||
|
)
|
||
|
|
||
|
type controlFn = func(ctx context.Context, network, address string, c syscall.RawConn) error
|
||
|
|
||
|
func addControlToListenConfig(lc *net.ListenConfig, fn controlFn) {
|
||
|
llc := *lc
|
||
|
lc.Control = func(network, address string, c syscall.RawConn) (err error) {
|
||
|
switch {
|
||
|
case llc.Control != nil:
|
||
|
if err = llc.Control(network, address, c); err != nil {
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
return fn(context.Background(), network, address, c)
|
||
|
}
|
||
|
}
|