From afdbb7cc8c33db222eecfa9e59d47fc7a2877229 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Tue, 5 Sep 2017 12:51:58 +1200 Subject: [PATCH] Add TCP Keepalive (#90) --- client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index d4d5a537..ecad7bdd 100644 --- a/client.go +++ b/client.go @@ -33,6 +33,9 @@ var ( // HTTPClient. The timeout includes connection time, any redirects, // and reading the response body. HTTPClientTimeout = 60 * time.Second + // TCPKeepAlive specifies the keep-alive period for an active network + // connection. If zero, keep-alives are not enabled. + TCPKeepAlive = 60 * time.Second ) // Client represents a connection with the APNs @@ -63,7 +66,11 @@ func NewClient(certificate tls.Certificate) *Client { transport := &http2.Transport{ TLSClientConfig: tlsConfig, DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) { - return tls.DialWithDialer(&net.Dialer{Timeout: TLSDialTimeout}, network, addr, cfg) + dialer := &net.Dialer{ + Timeout: TLSDialTimeout, + KeepAlive: TCPKeepAlive, + } + return tls.DialWithDialer(dialer, network, addr, cfg) }, } return &Client{