@ -134,6 +134,9 @@ type MConnConfig struct {
// Maximum wait time for pongs
// Maximum wait time for pongs
PongTimeout time . Duration ` mapstructure:"pong_timeout" `
PongTimeout time . Duration ` mapstructure:"pong_timeout" `
// Process/Transport Start time
StartTime time . Time ` mapstructure:",omitempty" `
}
}
// DefaultMConnConfig returns the default config.
// DefaultMConnConfig returns the default config.
@ -145,33 +148,17 @@ func DefaultMConnConfig() MConnConfig {
FlushThrottle : defaultFlushThrottle ,
FlushThrottle : defaultFlushThrottle ,
PingInterval : defaultPingInterval ,
PingInterval : defaultPingInterval ,
PongTimeout : defaultPongTimeout ,
PongTimeout : defaultPongTimeout ,
StartTime : time . Now ( ) ,
}
}
}
}
// NewMConnection wraps net.Conn and creates multiplex connection
// NewMConnection wraps net.Conn and creates multiplex connection with a config
func NewMConnection (
func NewMConnection (
logger log . Logger ,
logger log . Logger ,
conn net . Conn ,
conn net . Conn ,
chDescs [ ] * ChannelDescriptor ,
chDescs [ ] * ChannelDescriptor ,
onReceive receiveCbFunc ,
onReceive receiveCbFunc ,
onError errorCbFunc ,
onError errorCbFunc ,
) * MConnection {
return NewMConnectionWithConfig (
logger ,
conn ,
chDescs ,
onReceive ,
onError ,
DefaultMConnConfig ( ) )
}
// NewMConnectionWithConfig wraps net.Conn and creates multiplex connection with a config
func NewMConnectionWithConfig (
logger log . Logger ,
conn net . Conn ,
chDescs [ ] * ChannelDescriptor ,
onReceive receiveCbFunc ,
onError errorCbFunc ,
config MConnConfig ,
config MConnConfig ,
) * MConnection {
) * MConnection {
if config . PongTimeout >= config . PingInterval {
if config . PongTimeout >= config . PingInterval {
@ -183,8 +170,8 @@ func NewMConnectionWithConfig(
conn : conn ,
conn : conn ,
bufConnReader : bufio . NewReaderSize ( conn , minReadBufferSize ) ,
bufConnReader : bufio . NewReaderSize ( conn , minReadBufferSize ) ,
bufConnWriter : bufio . NewWriterSize ( conn , minWriteBufferSize ) ,
bufConnWriter : bufio . NewWriterSize ( conn , minWriteBufferSize ) ,
sendMonitor : flowrate . New ( 0 , 0 ) ,
recvMonitor : flowrate . New ( 0 , 0 ) ,
sendMonitor : flowrate . New ( config . StartTime , 0 , 0 ) ,
recvMonitor : flowrate . New ( config . StartTime , 0 , 0 ) ,
send : make ( chan struct { } , 1 ) ,
send : make ( chan struct { } , 1 ) ,
pong : make ( chan struct { } , 1 ) ,
pong : make ( chan struct { } , 1 ) ,
onReceive : onReceive ,
onReceive : onReceive ,