From e3b1fdd95125624732938bbf4e29b6950c798dbf Mon Sep 17 00:00:00 2001 From: Daichi Tomaru Date: Tue, 20 Dec 2022 08:42:34 +0900 Subject: [PATCH] Fixed to avoid panic when keep alive is 0 #531. Signed-off-by: Daichi Tomaru --- ping.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ping.go b/ping.go index 857aa0e..91cd3de 100644 --- a/ping.go +++ b/ping.go @@ -32,16 +32,16 @@ import ( func keepalive(c *client, conn io.Writer) { defer c.workers.Done() DEBUG.Println(PNG, "keepalive starting") - var checkInterval int64 + var checkInterval time.Duration var pingSent time.Time if c.options.KeepAlive > 10 { - checkInterval = 5 + checkInterval = 5 * time.Second } else { - checkInterval = c.options.KeepAlive / 2 + checkInterval = time.Duration(c.options.KeepAlive) * time.Second / 2 } - intervalTicker := time.NewTicker(time.Duration(checkInterval * int64(time.Second))) + intervalTicker := time.NewTicker(checkInterval) defer intervalTicker.Stop() for {