Sockopt: Add dialTimeout

This commit is contained in:
风扇滑翔翼 2025-03-06 21:41:38 +00:00 committed by GitHub
parent 16eee1b89c
commit 43b57825fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 51 additions and 33 deletions

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,
}