quit chan struct{}
flushTimer *cmn.ThrottleTimer // flush writes as necessary but throttled.
- pingTimer *cmn.RepeatTimer // send pings periodically
- chStatsTimer *cmn.RepeatTimer // update channel stats periodically
+ pingTimer *time.Ticker // send pings periodically
+ chStatsTimer *time.Ticker // update channel stats periodically
LocalAddress *NetAddress
RemoteAddress *NetAddress
onError: onError,
config: config,
+ pingTimer: time.NewTicker(pingTimeout),
+ chStatsTimer: time.NewTicker(updateState),
+
LocalAddress: NewNetAddress(conn.LocalAddr()),
RemoteAddress: NewNetAddress(conn.RemoteAddr()),
}
c.BaseService.OnStart()
c.quit = make(chan struct{})
c.flushTimer = cmn.NewThrottleTimer("flush", flushThrottle)
- c.pingTimer = cmn.NewRepeatTimer("ping", pingTimeout)
- c.chStatsTimer = cmn.NewRepeatTimer("chStats", updateState)
go c.sendRoutine()
go c.recvRoutine()
return nil
func (c *MConnection) OnStop() {
c.BaseService.OnStop()
c.flushTimer.Stop()
- c.pingTimer.Stop()
- c.chStatsTimer.Stop()
if c.quit != nil {
close(c.quit)
}
// NOTE: flushTimer.Set() must be called every time
// something is written to .bufWriter.
c.flush()
- case <-c.chStatsTimer.Ch:
+ case <-c.chStatsTimer.C:
for _, channel := range c.channels {
channel.updateStats()
}
- case <-c.pingTimer.Ch:
+ case <-c.pingTimer.C:
log.Debug("Send Ping")
wire.WriteByte(packetTypePing, c.bufWriter, &n, &err)
c.sendMonitor.Update(int(n))
default:
cmn.PanicSanity(cmn.Fmt("Unknown message type %X", pktType))
}
-
- // TODO: shouldn't this go in the sendRoutine?
- // Better to send a ping packet when *we* haven't sent anything for a while.
- c.pingTimer.Reset()
}
// Cleanup