Skip to content

Commit

Permalink
Add TCP idle timeout (sideshow#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
closer committed Feb 21, 2018
1 parent df275e5 commit 403af23
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ var (
// TCPKeepAlive specifies the keep-alive period for an active network
// connection. If zero, keep-alives are not enabled.
TCPKeepAlive = 60 * time.Second
// TCPIdleTimeout specifies the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// If zero, are no limit.
TCPIdleTimeout = 0 * time.Second
)

// DialTLS is the default dial function for creating TLS connections for
Expand Down Expand Up @@ -79,10 +84,11 @@ func NewClient(certificate tls.Certificate) *Client {
if len(certificate.Certificate) > 0 {
tlsConfig.BuildNameToCertificate()
}
transport := &http2.Transport{
TLSClientConfig: tlsConfig,
DialTLS: DialTLS,
}
transport, _ := http2.ConfigureTransport(&http.Transport{
IdleConnTimeout: TCPIdleTimeout,
})
transport.TLSClientConfig = tlsConfig
transport.DialTLS = DialTLS
return &Client{
HTTPClient: &http.Client{
Transport: transport,
Expand All @@ -102,9 +108,10 @@ func NewClient(certificate tls.Certificate) *Client {
// notifications; don’t repeatedly open and close connections. APNs treats rapid
// connection and disconnection as a denial-of-service attack.
func NewTokenClient(token *token.Token) *Client {
transport := &http2.Transport{
DialTLS: DialTLS,
}
transport, _ := http2.ConfigureTransport(&http.Transport{
IdleConnTimeout: TCPIdleTimeout,
})
transport.DialTLS = DialTLS
return &Client{
Token: token,
HTTPClient: &http.Client{
Expand Down

0 comments on commit 403af23

Please sign in to comment.