mirror of https://github.com/golang/go.git
net: use same TCP Keep Alive interval between dial and accept
Fixes #31510 Change-Id: I601d114b617a055380bf3c805e2d9a9b0795b656 Reviewed-on: https://go-review.googlesource.com/c/go/+/175259 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
d199369aab
commit
b98cecff88
|
|
@ -12,6 +12,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// defaultTCPKeepAlive is a default constant value for TCPKeepAlive times
|
||||||
|
// See golang.org/issue/31510
|
||||||
|
const (
|
||||||
|
defaultTCPKeepAlive = 15 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// A Dialer contains options for connecting to an address.
|
// A Dialer contains options for connecting to an address.
|
||||||
//
|
//
|
||||||
// The zero value for each field is equivalent to dialing
|
// The zero value for each field is equivalent to dialing
|
||||||
|
|
@ -425,7 +431,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (Conn
|
||||||
setKeepAlive(tc.fd, true)
|
setKeepAlive(tc.fd, true)
|
||||||
ka := d.KeepAlive
|
ka := d.KeepAlive
|
||||||
if d.KeepAlive == 0 {
|
if d.KeepAlive == 0 {
|
||||||
ka = 15 * time.Second
|
ka = defaultTCPKeepAlive
|
||||||
}
|
}
|
||||||
setKeepAlivePeriod(tc.fd, ka)
|
setKeepAlivePeriod(tc.fd, ka)
|
||||||
testHookSetKeepAlive(ka)
|
testHookSetKeepAlive(ka)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *TCPConn) readFrom(r io.Reader) (int64, error) {
|
func (c *TCPConn) readFrom(r io.Reader) (int64, error) {
|
||||||
|
|
@ -50,7 +49,7 @@ func (ln *TCPListener) accept() (*TCPConn, error) {
|
||||||
setKeepAlive(fd, true)
|
setKeepAlive(fd, true)
|
||||||
ka := ln.lc.KeepAlive
|
ka := ln.lc.KeepAlive
|
||||||
if ln.lc.KeepAlive == 0 {
|
if ln.lc.KeepAlive == 0 {
|
||||||
ka = 3 * time.Minute
|
ka = defaultTCPKeepAlive
|
||||||
}
|
}
|
||||||
setKeepAlivePeriod(fd, ka)
|
setKeepAlivePeriod(fd, ka)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
||||||
|
|
@ -146,7 +145,7 @@ func (ln *TCPListener) accept() (*TCPConn, error) {
|
||||||
setKeepAlive(fd, true)
|
setKeepAlive(fd, true)
|
||||||
ka := ln.lc.KeepAlive
|
ka := ln.lc.KeepAlive
|
||||||
if ln.lc.KeepAlive == 0 {
|
if ln.lc.KeepAlive == 0 {
|
||||||
ka = 3 * time.Minute
|
ka = defaultTCPKeepAlive
|
||||||
}
|
}
|
||||||
setKeepAlivePeriod(fd, ka)
|
setKeepAlivePeriod(fd, ka)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue