2018-04-04 13:28:35 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-04-04 13:50:34 +00:00
|
|
|
type ClientConnHandler interface {
|
2018-04-04 13:28:35 +00:00
|
|
|
ConnectionHandler
|
|
|
|
GetReconnectInterval() time.Duration
|
|
|
|
GetReconnectTryTime() int
|
|
|
|
}
|
|
|
|
|
2018-04-04 13:50:34 +00:00
|
|
|
type ClientConnHandlers struct {
|
2018-04-04 13:28:35 +00:00
|
|
|
ConnectionHandlers
|
|
|
|
|
|
|
|
ReconnectInterval time.Duration
|
|
|
|
ReconnectTryTime int
|
|
|
|
}
|
|
|
|
|
2018-04-04 13:50:34 +00:00
|
|
|
func (cch *ClientConnHandlers) GetReconnectInterval() time.Duration {
|
2018-04-04 13:28:35 +00:00
|
|
|
return cch.ReconnectInterval
|
|
|
|
}
|
|
|
|
|
2018-04-04 13:50:34 +00:00
|
|
|
func (cch *ClientConnHandlers) GetReconnectTryTime() int {
|
2018-04-04 13:28:35 +00:00
|
|
|
return cch.ReconnectTryTime
|
|
|
|
}
|
|
|
|
|
2018-04-04 13:50:34 +00:00
|
|
|
func (cch *ClientConnHandlers) Validate() error {
|
2018-04-04 13:28:35 +00:00
|
|
|
if err := cch.ConnectionHandlers.Validate(); nil != err {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if cch.ReconnectInterval <= 0 {
|
|
|
|
cch.ReconnectInterval = DefaultReconnectInterval
|
|
|
|
}
|
|
|
|
|
|
|
|
if cch.ReconnectTryTime <= 0 {
|
|
|
|
cch.ReconnectTryTime = DefaultReconnectTryTime
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|