Sockopt: Add dialTimeout

This commit is contained in:
风扇滑翔翼
2025-03-06 21:41:38 +00:00
committed by GitHub
parent 16eee1b89c
commit 43b57825fa
4 changed files with 51 additions and 33 deletions
+5 -1
View File
@@ -87,8 +87,12 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
if sockopt != nil && (sockopt.TcpKeepAliveInterval != 0 || sockopt.TcpKeepAliveIdle != 0) {
goStdKeepAlive = time.Duration(-1)
}
dialTimeout := time.Second * 16
if sockopt != nil && sockopt.DialTimeout > 0 {
dialTimeout = time.Second * time.Duration(sockopt.DialTimeout)
}
dialer := &net.Dialer{
Timeout: time.Second * 16,
Timeout: dialTimeout,
LocalAddr: resolveSrcAddr(dest.Network, src),
KeepAlive: goStdKeepAlive,
}