ing
This commit is contained in:
parent
68f1a7b519
commit
8ba623111b
|
@ -151,6 +151,8 @@ func handleConnection(s *server, soc *Socket, socketHandler SocketHandler) {
|
||||||
defer s.stopWg.Done()
|
defer s.stopWg.Done()
|
||||||
|
|
||||||
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
||||||
|
socketHandler.OnConnect(soc)
|
||||||
|
|
||||||
clientStopChan := make(chan struct{})
|
clientStopChan := make(chan struct{})
|
||||||
handleDoneChan := make(chan struct{})
|
handleDoneChan := make(chan struct{})
|
||||||
|
|
||||||
|
@ -159,11 +161,11 @@ func handleConnection(s *server, soc *Socket, socketHandler SocketHandler) {
|
||||||
select {
|
select {
|
||||||
case <-s.stopChan:
|
case <-s.stopChan:
|
||||||
close(clientStopChan)
|
close(clientStopChan)
|
||||||
soc.Close()
|
|
||||||
<-handleDoneChan
|
<-handleDoneChan
|
||||||
case <-handleDoneChan:
|
case <-handleDoneChan:
|
||||||
close(clientStopChan)
|
close(clientStopChan)
|
||||||
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", soc.RemoteAddr()))
|
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is disconnected.", soc.RemoteAddr()))
|
||||||
|
socketHandler.OnDisconnect(soc)
|
||||||
soc.Close()
|
soc.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ type SocketHandler interface {
|
||||||
// Handshake do handshake client and server
|
// Handshake do handshake client and server
|
||||||
// id is identity of client socket. if id is nil, disallow connection
|
// id is identity of client socket. if id is nil, disallow connection
|
||||||
Handshake(ctx *fasthttp.RequestCtx) (id interface{}, extensionsHeader *fasthttp.ResponseHeader)
|
Handshake(ctx *fasthttp.RequestCtx) (id interface{}, extensionsHeader *fasthttp.ResponseHeader)
|
||||||
|
OnConnect(soc *Socket)
|
||||||
Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
|
Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
|
||||||
|
OnDisconnect(soc *Socket)
|
||||||
|
|
||||||
GetMaxMessageSize() int64
|
GetMaxMessageSize() int64
|
||||||
GetWriteTimeout() time.Duration
|
GetWriteTimeout() time.Duration
|
||||||
|
|
|
@ -30,11 +30,18 @@ type SocketHandlers struct {
|
||||||
func (sh *SocketHandlers) Handshake(ctx *fasthttp.RequestCtx) (id interface{}, extensionsHeader *fasthttp.ResponseHeader) {
|
func (sh *SocketHandlers) Handshake(ctx *fasthttp.RequestCtx) (id interface{}, extensionsHeader *fasthttp.ResponseHeader) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
func (sh *SocketHandlers) OnConnect(soc *Socket) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
func (sh *SocketHandlers) Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{}) {
|
||||||
// no op
|
// no op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) OnDisconnect(soc *Socket) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) GetMaxMessageSize() int64 {
|
func (sh *SocketHandlers) GetMaxMessageSize() int64 {
|
||||||
return sh.MaxMessageSize
|
return sh.MaxMessageSize
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user