server-go/socket/client-conn-handler.go

46 lines
844 B
Go
Raw Normal View History

2018-04-05 16:21:13 +00:00
package socket
2018-04-04 13:28:35 +00:00
import (
"time"
2018-04-05 16:21:13 +00:00
"git.loafle.net/commons/server-go"
2018-04-04 13:28:35 +00:00
)
2018-04-04 13:50:34 +00:00
type ClientConnHandler interface {
2018-04-05 16:21:13 +00:00
server.ConnectionHandler
2018-04-04 13:28:35 +00:00
GetReconnectInterval() time.Duration
GetReconnectTryTime() int
}
2018-04-04 13:50:34 +00:00
type ClientConnHandlers struct {
2018-04-05 16:21:13 +00:00
server.ConnectionHandlers
2018-04-04 13:28:35 +00:00
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 {
2018-04-05 16:21:13 +00:00
cch.ReconnectInterval = server.DefaultReconnectInterval
2018-04-04 13:28:35 +00:00
}
if cch.ReconnectTryTime <= 0 {
2018-04-05 16:21:13 +00:00
cch.ReconnectTryTime = server.DefaultReconnectTryTime
2018-04-04 13:28:35 +00:00
}
return nil
}