From aafa906038753b49c6349ba6cf076f84443c167a Mon Sep 17 00:00:00 2001 From: franklin Date: Mon, 20 Mar 2017 13:16:19 +0100 Subject: [PATCH] add RedialDelay on client --- client.go | 9 ++++++++- common.go | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index ea6086e..03c1d65 100644 --- a/client.go +++ b/client.go @@ -57,6 +57,10 @@ type Client struct { // Default value is DefaultRequestTimeout. RequestTimeout time.Duration + // Time to wait for redial. + // Default value is DefaultRedialDelay. + RedialDelay time.Duration + // Disable data compression. // By default data compression is enabled. DisableCompression bool @@ -135,6 +139,9 @@ func (c *Client) Start() { if c.RequestTimeout <= 0 { c.RequestTimeout = DefaultRequestTimeout } + if c.RedialDelay <= 0 { + c.RedialDelay = DefaultRedialDelay + } if c.SendBufferSize <= 0 { c.SendBufferSize = DefaultBufferSize } @@ -665,7 +672,7 @@ func clientHandler(c *Client) { select { case <-c.clientStopChan: return - case <-time.After(time.Second): + case <-time.After(c.RedialDelay): } continue } diff --git a/common.go b/common.go index 3a69dc1..d21385d 100644 --- a/common.go +++ b/common.go @@ -16,6 +16,9 @@ const ( // DefaultRequestTimeout is the default timeout for client request. DefaultRequestTimeout = 20 * time.Second + // DefaultRedialDelay is the default delay before trying to redial. + DefaultRedialDelay = 1 * time.Second + // DefaultPendingMessages is the default number of pending messages // handled by Client and Server. DefaultPendingMessages = 32 * 1024