From 23bd2b6acf7eceb4987fe18d530be30f2d88b42a Mon Sep 17 00:00:00 2001 From: terry-xiaoyu Date: Tue, 23 Jan 2018 18:11:33 +0800 Subject: [PATCH] Add TCP Idle TimeOut #24 --- client.go | 7 +++++++ vendor/golang.org/x/net/http2/transport.go | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 221a7df6..0b8328c1 100644 --- a/client.go +++ b/client.go @@ -37,6 +37,12 @@ var ( // TCPKeepAlive specifies the keep-alive period for an active network // connection. If zero, keep-alives are not enabled. TCPKeepAlive = 60 * time.Second + + // TCPIdleTimeOut is the maximum amount of time an idle + // (keep-alive) connection will remain idle before closing + // itself. + // Zero means no limit. + TCPIdleTimeOut = 0 * time.Second ) // DialTLS is the default dial function for creating TLS connections for @@ -82,6 +88,7 @@ func NewClient(certificate tls.Certificate) *Client { transport := &http2.Transport{ TLSClientConfig: tlsConfig, DialTLS: DialTLS, + IdleConnTimeout: TCPIdleTimeOut, } return &Client{ HTTPClient: &http.Client{ diff --git a/vendor/golang.org/x/net/http2/transport.go b/vendor/golang.org/x/net/http2/transport.go index 84d042d4..42a06992 100644 --- a/vendor/golang.org/x/net/http2/transport.go +++ b/vendor/golang.org/x/net/http2/transport.go @@ -93,6 +93,12 @@ type Transport struct { // to mean no limit. MaxHeaderListSize uint32 + // IdleConnTimeout is the maximum amount of time an idle + // (keep-alive) connection will remain idle before closing + // itself. + // Zero means no limit. + IdleConnTimeout time.Duration + // t1, if non-nil, is the standard library Transport using // this transport. Its settings are used (but not its // RoundTrip method, etc). @@ -486,7 +492,7 @@ func (t *Transport) newClientConn(c net.Conn, singleUse bool) (*ClientConn, erro wantSettingsAck: true, pings: make(map[[8]byte]chan struct{}), } - if d := t.idleConnTimeout(); d != 0 { + if d := t.IdleConnTimeout; d != 0 { cc.idleTimeout = d cc.idleTimer = time.AfterFunc(d, cc.onIdleTimeout) }