]> Cypherpunks repositories - gostls13.git/commitdiff
net: use same TCP Keep Alive interval between dial and accept
authorDong-hee Na <donghee.na92@gmail.com>
Sun, 5 May 2019 08:23:20 +0000 (17:23 +0900)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 6 May 2019 18:01:09 +0000 (18:01 +0000)
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>

src/net/dial.go
src/net/tcpsock_plan9.go
src/net/tcpsock_posix.go

index e2e60530a9b2e5de7f924dac4f59b2472974d912..4d55a95ddf6b9b6359b5544cad5af842dd88b213 100644 (file)
@@ -12,6 +12,12 @@ import (
        "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.
 //
 // 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)
                ka := d.KeepAlive
                if d.KeepAlive == 0 {
-                       ka = 15 * time.Second
+                       ka = defaultTCPKeepAlive
                }
                setKeepAlivePeriod(tc.fd, ka)
                testHookSetKeepAlive(ka)
index e538f558653dd720d930ce3326e022c0f67c0dfa..e2e835957c0396dec4225134417a382552b59c49 100644 (file)
@@ -8,7 +8,6 @@ import (
        "context"
        "io"
        "os"
-       "time"
 )
 
 func (c *TCPConn) readFrom(r io.Reader) (int64, error) {
@@ -50,7 +49,7 @@ func (ln *TCPListener) accept() (*TCPConn, error) {
                setKeepAlive(fd, true)
                ka := ln.lc.KeepAlive
                if ln.lc.KeepAlive == 0 {
-                       ka = 3 * time.Minute
+                       ka = defaultTCPKeepAlive
                }
                setKeepAlivePeriod(fd, ka)
        }
index 14d383b74d2632984c215b081c3f9a9340bbfa4c..e32d5d7ee3508287a1bd2b5172837609607a11e5 100644 (file)
@@ -11,7 +11,6 @@ import (
        "io"
        "os"
        "syscall"
-       "time"
 )
 
 func sockaddrToTCP(sa syscall.Sockaddr) Addr {
@@ -146,7 +145,7 @@ func (ln *TCPListener) accept() (*TCPConn, error) {
                setKeepAlive(fd, true)
                ka := ln.lc.KeepAlive
                if ln.lc.KeepAlive == 0 {
-                       ka = 3 * time.Minute
+                       ka = defaultTCPKeepAlive
                }
                setKeepAlivePeriod(fd, ka)
        }