diff options
Diffstat (limited to 'libgo/go/net/dial.go')
-rw-r--r-- | libgo/go/net/dial.go | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/libgo/go/net/dial.go b/libgo/go/net/dial.go index b1a5ca7..1dd8690 100644 --- a/libgo/go/net/dial.go +++ b/libgo/go/net/dial.go @@ -44,22 +44,31 @@ type Dialer struct { // If nil, a local address is automatically chosen. LocalAddr Addr - // DualStack enables RFC 6555-compliant "Happy Eyeballs" - // dialing when the network is "tcp" and the host in the - // address parameter resolves to both IPv4 and IPv6 addresses. - // This allows a client to tolerate networks where one address - // family is silently broken. + // DualStack previously enabled RFC 6555 Fast Fallback + // support, also known as "Happy Eyeballs", in which IPv4 is + // tried soon if IPv6 appears to be misconfigured and + // hanging. + // + // Deprecated: Fast Fallback is enabled by default. To + // disable, set FallbackDelay to a negative value. DualStack bool // FallbackDelay specifies the length of time to wait before - // spawning a fallback connection, when DualStack is enabled. + // spawning a RFC 6555 Fast Fallback connection. That is, this + // is the amount of time to wait for IPv6 to succeed before + // assuming that IPv6 is misconfigured and falling back to + // IPv4. + // // If zero, a default delay of 300ms is used. + // A negative value disables Fast Fallback support. FallbackDelay time.Duration // KeepAlive specifies the keep-alive period for an active // network connection. - // If zero, keep-alives are not enabled. Network protocols + // If zero, keep-alives are enabled if supported by the protocol + // and operating system. Network protocols or operating systems // that do not support keep-alives ignore this field. + // If negative, keep-alives are disabled. KeepAlive time.Duration // Resolver optionally specifies an alternate resolver to use. @@ -81,6 +90,8 @@ type Dialer struct { Control func(network, address string, c syscall.RawConn) error } +func (d *Dialer) dualStack() bool { return d.FallbackDelay >= 0 } + func minNonzeroTime(a, b time.Time) time.Time { if a.IsZero() { return b @@ -393,7 +404,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn } var primaries, fallbacks addrList - if d.DualStack && network == "tcp" { + if d.dualStack() && network == "tcp" { primaries, fallbacks = addrs.partition(isIPv4) } else { primaries = addrs @@ -409,10 +420,14 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn return nil, err } - if tc, ok := c.(*TCPConn); ok && d.KeepAlive > 0 { + if tc, ok := c.(*TCPConn); ok && d.KeepAlive >= 0 { setKeepAlive(tc.fd, true) - setKeepAlivePeriod(tc.fd, d.KeepAlive) - testHookSetKeepAlive() + ka := d.KeepAlive + if d.KeepAlive == 0 { + ka = 15 * time.Second + } + setKeepAlivePeriod(tc.fd, ka) + testHookSetKeepAlive(ka) } return c, nil } |