ing
This commit is contained in:
parent
4f607dd971
commit
a1cf7963b5
10
server.go
10
server.go
|
@ -69,12 +69,13 @@ func (s *server) Stop() {
|
|||
logging.Logger().Warn("Server: server must be started before stopping it")
|
||||
return
|
||||
}
|
||||
|
||||
s.sh.Destroy(s.ctx)
|
||||
|
||||
close(s.stopChan)
|
||||
s.stopWg.Wait()
|
||||
s.stopChan = nil
|
||||
|
||||
s.sh.OnStop(s.ctx)
|
||||
|
||||
logging.Logger().Infof("Server[%s] is stopped", s.sh.GetName())
|
||||
}
|
||||
|
||||
|
@ -83,7 +84,10 @@ func (s *server) Context() ServerContext {
|
|||
}
|
||||
|
||||
func handleServer(s *server) {
|
||||
defer s.stopWg.Done()
|
||||
defer func() {
|
||||
s.sh.OnStop(s.ctx)
|
||||
s.stopWg.Done()
|
||||
}()
|
||||
|
||||
logging.Logger().Infof("Server[%s] is started", s.sh.GetName())
|
||||
s.sh.OnStart(s.ctx)
|
||||
|
|
|
@ -12,14 +12,16 @@ type ServerHandler interface {
|
|||
|
||||
OnError(serverCTX ServerContext, conn net.Conn, status int, reason error)
|
||||
|
||||
// OnStop invoked when server is stopped
|
||||
OnStop(serverCTX ServerContext)
|
||||
|
||||
// Destroy invoked when server will destroy
|
||||
// If you override ths method, must call
|
||||
//
|
||||
// func (sh *ServerHandler) OnStop() {
|
||||
// func (sh *ServerHandler) Destroy() {
|
||||
// ...
|
||||
// sh.ServerHandler.OnStop()
|
||||
// sh.ServerHandler.Destroy()
|
||||
// }
|
||||
OnStop(serverCTX ServerContext)
|
||||
Destroy(serverCTX ServerContext)
|
||||
|
||||
GetName() string
|
||||
GetSocketHandler() SocketHandler
|
||||
|
|
|
@ -45,9 +45,13 @@ func (sh *ServerHandlers) OnError(serverCTX ServerContext, conn net.Conn, status
|
|||
logging.Logger().Errorf("Server: error status: %d, reason: %v, [%v]", status, reason, conn)
|
||||
}
|
||||
|
||||
// OnStop invoked when server is stopped
|
||||
// If you override ths method, must call
|
||||
func (sh *ServerHandlers) OnStop(serverCTX ServerContext) {
|
||||
// no op
|
||||
}
|
||||
|
||||
// Destroy invoked when server is stopped
|
||||
// If you override ths method, must call
|
||||
func (sh *ServerHandlers) Destroy(serverCTX ServerContext) {
|
||||
sh.SocketHandler.Destroy()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user