This commit is contained in:
crusader 2017-11-30 16:15:20 +09:00
parent 3e3a884c4d
commit 526dce9cce

View File

@ -81,21 +81,7 @@ func (s *rpcServlet) Start(parentCTX cuc.Context, conn interface{}, doneChan cha
}
func (s *rpcServlet) Stop() {
if s.stopChan == nil {
panic("Server: server must be started before stopping it")
}
close(s.stopChan)
s.stopWg.Wait()
s.sh.Destroy(s.ctx)
s.stopChan = nil
s.responseQueueChan = nil
s.conn = nil
s.serverCodec = nil
logging.Logger().Info(fmt.Sprintf("Servlet is stopped"))
s.destroy(nil)
}
func (s *rpcServlet) Send(method string, args ...interface{}) (err error) {
@ -116,6 +102,26 @@ func (s *rpcServlet) Context() ServletContext {
return s.ctx
}
func (s *rpcServlet) destroy(err error) {
if s.stopChan == nil {
panic("Server: server must be started before stopping it")
}
close(s.stopChan)
s.stopWg.Wait()
s.sh.Destroy(s.ctx)
s.stopChan = nil
s.responseQueueChan = nil
s.conn = nil
s.serverCodec = nil
logging.Logger().Info(fmt.Sprintf("Servlet is stopped"))
s.doneChan <- err
}
func handleServlet(s *rpcServlet) {
var err error
@ -123,8 +129,7 @@ func handleServlet(s *rpcServlet) {
defer func() {
s.stopWg.Done()
s.Stop()
s.doneChan <- err
s.destroy(err)
}()
subStopChan := make(chan struct{})