deprecated_overflow_gateway.../socket_handlers.go
crusader e2ef11e395 ing
2017-08-31 19:33:40 +09:00

91 lines
2.1 KiB
Go

package overflow_gateway_websocket
import (
"log"
"time"
)
const (
// DefaultWriteTimeout is default value of Write Timeout
DefaultWriteTimeout = 0
// DefaultReadTimeout is default value of Read Timeout
DefaultReadTimeout = 0
// DefaultPongTimeout is default value of Pong Timeout
DefaultPongTimeout = 60 * time.Second
// DefaultPingTimeout is default value of Ping Timeout
DefaultPingTimeout = 10 * time.Second
// DefaultPingPeriod is default value of Ping Period
DefaultPingPeriod = (DefaultPongTimeout * 9) / 10
// DefaultMaxMessageSize is default value of Max Message Size
DefaultMaxMessageSize = 1024
)
// SocketOptions is configuration of the websocket server
type SocketHandlers struct {
onDisconnected func(soc Socket)
Protocol ProtocolHandler
MaxMessageSize int64
WriteTimeout time.Duration
ReadTimeout time.Duration
PongTimeout time.Duration
PingTimeout time.Duration
PingPeriod time.Duration
BinaryMessage bool
}
func (sh *SocketHandlers) GetMaxMessageSize() int64 {
return sh.MaxMessageSize
}
func (sh *SocketHandlers) GetWriteTimeout() time.Duration {
return sh.WriteTimeout
}
func (sh *SocketHandlers) GetReadTimeout() time.Duration {
return sh.ReadTimeout
}
func (sh *SocketHandlers) GetPongTimeout() time.Duration {
return sh.PongTimeout
}
func (sh *SocketHandlers) GetPingTimeout() time.Duration {
return sh.PingTimeout
}
func (sh *SocketHandlers) GetPingPeriod() time.Duration {
return sh.PingPeriod
}
func (sh *SocketHandlers) IsBinaryMessage() bool {
return sh.BinaryMessage
}
func (sh *SocketHandlers) GetProtocol() ProtocolHandler {
return sh.Protocol
}
// Validate validates the configuration
func (sh *SocketHandlers) Validate() {
if nil == sh.Protocol {
log.Fatalln("Protocol must be specified.")
}
if sh.WriteTimeout < 0 {
sh.WriteTimeout = DefaultWriteTimeout
}
if sh.ReadTimeout < 0 {
sh.ReadTimeout = DefaultReadTimeout
}
if sh.PongTimeout < 0 {
sh.PongTimeout = DefaultPongTimeout
}
if sh.PingPeriod <= 0 {
sh.PingPeriod = DefaultPingPeriod
}
if sh.MaxMessageSize <= 0 {
sh.MaxMessageSize = DefaultMaxMessageSize
}
}