This commit is contained in:
crusader 2017-11-10 17:43:11 +09:00
parent 944de8ecf5
commit 42c49a5914

View File

@ -9,19 +9,42 @@ import (
type SocketHandler interface { type SocketHandler interface {
// Init invoked when server is stated // Init invoked when server is stated
// If you override ths method, must call // If you override ths method, must call
//
// func (sh *SocketHandler) Init() error {
// if err := sh.SocketHandlers.Init(); nil != err {
// return err
// }
// ...
// return nil
// }
Init() error Init() error
// Handshake do handshake client and server // Handshake do handshake client and server
// id is identity of client socket. if id is "", disallow connection // id is identity of client socket. if id is "", disallow connection
Handshake(ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader) Handshake(ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader)
// OnConnect invoked when client is connected // OnConnect invoked when client is connected
// If you override ths method, must call // If you override ths method, must call
//
// func (sh *SocketHandler) OnConnect(soc *cwf.Socket) {
// sh.SocketHandlers.OnConnect(soc)
// ...
// }
OnConnect(soc *Socket) OnConnect(soc *Socket)
Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{}) Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
// OnDisconnect invoked when client is disconnected // OnDisconnect invoked when client is disconnected
// If you override ths method, must call // If you override ths method, must call
//
// func (sh *SocketHandler) OnDisconnect(soc *cwf.Socket) {
// ...
// sh.SocketHandlers.OnDisconnect(soc)
// }
OnDisconnect(soc *Socket) OnDisconnect(soc *Socket)
// Destroy invoked when server is stopped // Destroy invoked when server is stopped
// If you override ths method, must call // If you override ths method, must call
//
// func (sh *SocketHandler) Destroy() {
// ...
// sh.SocketHandlers.Destroy()
// }
Destroy() Destroy()
GetSocket(id string) *Socket GetSocket(id string) *Socket
@ -36,5 +59,10 @@ type SocketHandler interface {
// Validate is check handler value // Validate is check handler value
// If you override ths method, must call // If you override ths method, must call
//
// func (sh *SocketHandlers) Validate() {
// sh.SocketHandlers.Validate()
// ...
// }
Validate() Validate()
} }