2018-04-05 15:15:29 +00:00
|
|
|
package socket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.loafle.net/commons/server-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ReadWriteHandler interface {
|
|
|
|
server.ReadWriteHandler
|
|
|
|
GetPongTimeout() time.Duration
|
|
|
|
GetPingTimeout() time.Duration
|
|
|
|
GetPingPeriod() time.Duration
|
|
|
|
|
|
|
|
IsEnableCompression() bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReadWriteHandlers struct {
|
|
|
|
server.ReadWriteHandlers
|
|
|
|
|
2018-04-09 12:11:52 +00:00
|
|
|
PongTimeout time.Duration `json:"pongTimeout"`
|
|
|
|
PingTimeout time.Duration `json:"pingTimeout"`
|
|
|
|
PingPeriod time.Duration `json:"pingPeriod"`
|
2018-04-05 15:15:29 +00:00
|
|
|
|
2018-04-09 12:11:52 +00:00
|
|
|
EnableCompression bool `json:"enableCompression"`
|
2018-04-05 15:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (rwh *ReadWriteHandlers) GetPongTimeout() time.Duration {
|
|
|
|
return rwh.PongTimeout
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetPingTimeout() time.Duration {
|
|
|
|
return rwh.PingTimeout
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) GetPingPeriod() time.Duration {
|
|
|
|
return rwh.PingPeriod
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) IsEnableCompression() bool {
|
|
|
|
return rwh.EnableCompression
|
|
|
|
}
|
|
|
|
func (rwh *ReadWriteHandlers) Validate() error {
|
|
|
|
if err := rwh.ReadWriteHandlers.Validate(); nil != err {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if rwh.PongTimeout <= 0 {
|
|
|
|
rwh.PongTimeout = server.DefaultPongTimeout
|
|
|
|
}
|
|
|
|
if rwh.PingTimeout <= 0 {
|
|
|
|
rwh.PingTimeout = server.DefaultPingTimeout
|
|
|
|
}
|
|
|
|
if rwh.PingPeriod <= 0 {
|
|
|
|
rwh.PingPeriod = (rwh.PingTimeout * 9) / 10
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|