Bettering ping method

pull/238/head
Shelikhoo 2016-08-15 19:13:18 +08:00
parent e382eaa59f
commit 0a49628555
No known key found for this signature in database
GPG Key ID: 7791BDB0709ABD21
1 changed files with 3 additions and 4 deletions

View File

@ -183,19 +183,18 @@ func (ws *wsconn) pingPong() {
ws.wlock.Lock() ws.wlock.Lock()
ws.wsc.WriteMessage(websocket.PingMessage, nil) ws.wsc.WriteMessage(websocket.PingMessage, nil)
ws.wlock.Unlock() ws.wlock.Unlock()
tick := time.NewTicker(time.Second * 30) tick := time.After(time.Second * 3)
select { select {
case <-pongRcv: case <-pongRcv:
break break
case <-tick.C: case <-tick:
if !ws.connClosing { if !ws.connClosing {
log.Debug("WS:Closing as ping is not responded~" + ws.wsc.UnderlyingConn().LocalAddr().String() + "-" + ws.wsc.UnderlyingConn().RemoteAddr().String()) log.Debug("WS:Closing as ping is not responded~" + ws.wsc.UnderlyingConn().LocalAddr().String() + "-" + ws.wsc.UnderlyingConn().RemoteAddr().String())
} }
ws.Close() ws.Close()
} }
<-tick.C <-time.After(time.Second * 27)
tick.Stop()
} }
return return