|
|
@ -22,8 +22,6 @@ const ( |
|
|
|
minReadBufferSize = 1024 |
|
|
|
minWriteBufferSize = 65536 |
|
|
|
updateStats = 2 * time.Second |
|
|
|
pingTimeout = 40 * time.Second |
|
|
|
pongTimeout = 60 * time.Second |
|
|
|
|
|
|
|
// some of these defaults are written in the user config
|
|
|
|
// flushThrottle, sendRate, recvRate
|
|
|
@ -36,6 +34,8 @@ const ( |
|
|
|
defaultSendRate = int64(512000) // 500KB/s
|
|
|
|
defaultRecvRate = int64(512000) // 500KB/s
|
|
|
|
defaultSendTimeout = 10 * time.Second |
|
|
|
defaultPingTimeout = 40 * time.Second |
|
|
|
defaultPongTimeout = 60 * time.Second |
|
|
|
) |
|
|
|
|
|
|
|
type receiveCbFunc func(chID byte, msgBytes []byte) |
|
|
@ -100,6 +100,9 @@ type MConnConfig struct { |
|
|
|
MaxMsgPacketPayloadSize int |
|
|
|
|
|
|
|
FlushThrottle time.Duration |
|
|
|
|
|
|
|
pingTimeout time.Duration |
|
|
|
pongTimeout time.Duration |
|
|
|
} |
|
|
|
|
|
|
|
func (cfg *MConnConfig) maxMsgPacketTotalSize() int { |
|
|
@ -113,6 +116,8 @@ func DefaultMConnConfig() *MConnConfig { |
|
|
|
RecvRate: defaultRecvRate, |
|
|
|
MaxMsgPacketPayloadSize: defaultMaxMsgPacketPayloadSize, |
|
|
|
FlushThrottle: defaultFlushThrottle, |
|
|
|
pingTimeout: defaultPingTimeout, |
|
|
|
pongTimeout: defaultPongTimeout, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -172,8 +177,8 @@ func (c *MConnection) OnStart() error { |
|
|
|
} |
|
|
|
c.quit = make(chan struct{}) |
|
|
|
c.flushTimer = cmn.NewThrottleTimer("flush", c.config.FlushThrottle) |
|
|
|
c.pingTimer = cmn.NewRepeatTimer("ping", pingTimeout) |
|
|
|
c.pongTimer = cmn.NewThrottleTimer("pong", pongTimeout) |
|
|
|
c.pingTimer = cmn.NewRepeatTimer("ping", c.config.pingTimeout) |
|
|
|
c.pongTimer = cmn.NewThrottleTimer("pong", c.config.pongTimeout) |
|
|
|
c.chStatsTimer = cmn.NewRepeatTimer("chStats", updateStats) |
|
|
|
go c.sendRoutine() |
|
|
|
go c.recvRoutine() |
|
|
|