From 526dce9cce9b63e37c8569092d73df753d8aa833 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 30 Nov 2017 16:15:20 +0900 Subject: [PATCH] ing --- servlet.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/servlet.go b/servlet.go index 1f3bfce..6c6d6f6 100644 --- a/servlet.go +++ b/servlet.go @@ -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{})