diff --git a/servlet.go b/servlet.go index db24038..0a5b61c 100644 --- a/servlet.go +++ b/servlet.go @@ -37,7 +37,7 @@ type servlet struct { stopWg sync.WaitGroup } -func (s *servlet) Start(parentCTX cuc.Context, reader interface{}, writer interface{}) error { +func (s *servlet) Start(parentCTX cuc.Context, reader interface{}, writer interface{}, doneChan chan<- struct{}) error { if nil == s.sh { panic("Servlet: servlet handler must be specified.") } @@ -65,7 +65,7 @@ func (s *servlet) Start(parentCTX cuc.Context, reader interface{}, writer interf s.messageQueueChan = make(chan *messageState, s.sh.GetPendingMessages()) s.stopWg.Add(1) - go handleServlet(s) + go handleServlet(s, doneChan) return nil } @@ -102,11 +102,13 @@ func (s *servlet) Context() ServletContext { return s.ctx } -func handleServlet(s *servlet) { +func handleServlet(s *servlet, doneChan chan<- struct{}) { defer s.stopWg.Done() - s.stopWg.Add(1) - go handleMessage(s) + messageStopChan := make(chan struct{}) + messageDoneChan := make(chan struct{}) + + go handleMessage(s, messageStopChan, messageDoneChan) for { requestCodec, err := s.sh.GetRequest(s.ctx, s.serverCodec, s.reader)