mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2026-04-22 16:17:16 +08:00
chore: add short circuit logic for dual stack dial to decrease unnecessary goroutine
This commit is contained in:
@@ -209,6 +209,12 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string,
|
||||
if len(ipv4s) == 0 && len(ipv6s) == 0 {
|
||||
return nil, ErrorNoIpAddress
|
||||
}
|
||||
if len(ipv4s) == 0 && len(ipv6s) != 0 {
|
||||
return dialFn(ctx, network, ipv6s, port, opt)
|
||||
}
|
||||
if len(ipv4s) != 0 && len(ipv6s) == 0 {
|
||||
return dialFn(ctx, network, ipv4s, port, opt)
|
||||
}
|
||||
|
||||
preferIPVersion := opt.prefer
|
||||
fallbackTicker := time.NewTicker(dualStackFallbackTimeout)
|
||||
@@ -289,6 +295,9 @@ func parallelDialContext(ctx context.Context, network string, ips []netip.Addr,
|
||||
if len(ips) == 0 {
|
||||
return nil, ErrorNoIpAddress
|
||||
}
|
||||
if len(ips) == 1 {
|
||||
return dialContext(ctx, network, ips[0], port, opt)
|
||||
}
|
||||
results := make(chan dialResult)
|
||||
returned := make(chan struct{})
|
||||
defer close(returned)
|
||||
|
||||
Reference in New Issue
Block a user