Skip to content

Commit afdbb7c

Browse files
authored
Add TCP Keepalive (#90)
1 parent 7588e8f commit afdbb7c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ var (
3333
// HTTPClient. The timeout includes connection time, any redirects,
3434
// and reading the response body.
3535
HTTPClientTimeout = 60 * time.Second
36+
// TCPKeepAlive specifies the keep-alive period for an active network
37+
// connection. If zero, keep-alives are not enabled.
38+
TCPKeepAlive = 60 * time.Second
3639
)
3740

3841
// Client represents a connection with the APNs
@@ -63,7 +66,11 @@ func NewClient(certificate tls.Certificate) *Client {
6366
transport := &http2.Transport{
6467
TLSClientConfig: tlsConfig,
6568
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
66-
return tls.DialWithDialer(&net.Dialer{Timeout: TLSDialTimeout}, network, addr, cfg)
69+
dialer := &net.Dialer{
70+
Timeout: TLSDialTimeout,
71+
KeepAlive: TCPKeepAlive,
72+
}
73+
return tls.DialWithDialer(dialer, network, addr, cfg)
6774
},
6875
}
6976
return &Client{

0 commit comments

Comments
 (0)