This commit is contained in:
crusader 2017-08-31 19:33:40 +09:00
parent 8299f95f4c
commit e2ef11e395
3 changed files with 18 additions and 18 deletions

View File

@ -94,7 +94,7 @@ func (soc *socket) onDisconnected() {
}
func (soc *socket) onMessage(messageType int, r io.Reader) {
result := soc.sh.GetProtocolHandler().OnMessage(soc, messageType, r)
result := soc.sh.GetProtocol().OnMessage(soc, messageType, r)
if nil == result {
return
}

View File

@ -11,7 +11,7 @@ type SocketHandler interface {
GetPingTimeout() time.Duration
GetPingPeriod() time.Duration
IsBinaryMessage() bool
GetProtocolHandler() ProtocolHandler
GetProtocol() ProtocolHandler
Validate()
}

View File

@ -24,7 +24,7 @@ const (
type SocketHandlers struct {
onDisconnected func(soc Socket)
Handler ProtocolHandler
Protocol ProtocolHandler
MaxMessageSize int64
WriteTimeout time.Duration
@ -57,34 +57,34 @@ func (sh *SocketHandlers) IsBinaryMessage() bool {
return sh.BinaryMessage
}
func (sh *SocketHandlers) GetProtocolHandler() ProtocolHandler {
return sh.Handler
func (sh *SocketHandlers) GetProtocol() ProtocolHandler {
return sh.Protocol
}
// Validate validates the configuration
func (o *SocketHandlers) Validate() {
if nil == o.Handler {
log.Fatalf("Message Handler must specified.\n")
func (sh *SocketHandlers) Validate() {
if nil == sh.Protocol {
log.Fatalln("Protocol must be specified.")
}
if o.WriteTimeout < 0 {
o.WriteTimeout = DefaultWriteTimeout
if sh.WriteTimeout < 0 {
sh.WriteTimeout = DefaultWriteTimeout
}
if o.ReadTimeout < 0 {
o.ReadTimeout = DefaultReadTimeout
if sh.ReadTimeout < 0 {
sh.ReadTimeout = DefaultReadTimeout
}
if o.PongTimeout < 0 {
o.PongTimeout = DefaultPongTimeout
if sh.PongTimeout < 0 {
sh.PongTimeout = DefaultPongTimeout
}
if o.PingPeriod <= 0 {
o.PingPeriod = DefaultPingPeriod
if sh.PingPeriod <= 0 {
sh.PingPeriod = DefaultPingPeriod
}
if o.MaxMessageSize <= 0 {
o.MaxMessageSize = DefaultMaxMessageSize
if sh.MaxMessageSize <= 0 {
sh.MaxMessageSize = DefaultMaxMessageSize
}
}