modify timer

This commit is contained in:
zhouyuyan
2017-12-28 09:13:20 +08:00
parent 516db49db5
commit 9ad6590e83
+7 -7
View File
@@ -87,19 +87,19 @@ func (c *client) init() {
func (c *client) keepAlive(ch chan int) { func (c *client) keepAlive(ch chan int) {
defer close(ch) defer close(ch)
keepalive := time.Duration(c.info.keepalive * 3 / 2) keepalive := time.Duration(c.info.keepalive*3/2) * time.Second
timeTicker := time.NewTimer(keepalive * time.Second) timer := time.NewTimer(keepalive)
msgPool := c.mp msgPool := c.mp
for { for {
select { select {
case <-ch: case <-ch:
timeTicker.Reset(keepalive * time.Second) timer.Reset(keepalive)
case <-timeTicker.C: case <-timer.C:
log.Errorf("Client %s has exceeded timeout, disconnecting.\n", c.info.clientID) log.Error("Client exceeded timeout, disconnecting. clientID = ", c.info.clientID, " keepalive = ", c.info.keepalive)
msg := &Message{client: c, packet: DisconnectdPacket} msg := &Message{client: c, packet: DisconnectdPacket}
msgPool.queue <- msg msgPool.queue <- msg
timeTicker.Stop() timer.Stop()
return return
} }
} }
@@ -122,7 +122,7 @@ func (c *client) readLoop() {
break break
} }
// log.Info("recv buf: ", packet) // log.Info("recv buf: ", packet)
ch <- 1
msg := &Message{ msg := &Message{
client: c, client: c,
packet: packet, packet: packet,