From 0a49628555419ea3cd4e4c34efca0f21cef6c31b Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Mon, 15 Aug 2016 19:13:18 +0800 Subject: [PATCH] Bettering ping method --- transport/internet/ws/wsconn.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/transport/internet/ws/wsconn.go b/transport/internet/ws/wsconn.go index 57b961eb7..71693879e 100644 --- a/transport/internet/ws/wsconn.go +++ b/transport/internet/ws/wsconn.go @@ -183,19 +183,18 @@ func (ws *wsconn) pingPong() { ws.wlock.Lock() ws.wsc.WriteMessage(websocket.PingMessage, nil) ws.wlock.Unlock() - tick := time.NewTicker(time.Second * 30) + tick := time.After(time.Second * 3) select { case <-pongRcv: break - case <-tick.C: + case <-tick: if !ws.connClosing { log.Debug("WS:Closing as ping is not responded~" + ws.wsc.UnderlyingConn().LocalAddr().String() + "-" + ws.wsc.UnderlyingConn().RemoteAddr().String()) } ws.Close() } - <-tick.C - tick.Stop() + <-time.After(time.Second * 27) } return