diff --git a/app.go b/app.go index bd08ffee..f70c2ade 100644 --- a/app.go +++ b/app.go @@ -365,7 +365,7 @@ func listen() { app.running = true } -// SetDictionary set routes map +// SetDictionary sets routes map func SetDictionary(dict map[string]uint16) error { if app.running { return constants.ErrChangeDictionaryWhileRunning diff --git a/component.go b/component.go index 16f8a1af..07dfb451 100644 --- a/component.go +++ b/component.go @@ -101,5 +101,4 @@ func shutdownComponents() { for i := length - 1; i >= 0; i-- { remoteComp[i].comp.Shutdown() } - } diff --git a/service/handler.go b/service/handler.go index 7868aff1..9edc6751 100644 --- a/service/handler.go +++ b/service/handler.go @@ -101,14 +101,16 @@ func NewHandlerService( // Dispatch message to corresponding logic handler func (h *HandlerService) Dispatch(thread int) { - // close chLocalProcess & chCloseSession when application quit + // close chLocalProcess & chCloseSession when application quits + // TODO: This timer is being stopped multiple times, it probably doesn't need to be stopped here defer timer.GlobalTicker.Stop() - // handle packet that sent to chLocalProcess for { + // Calls to remote servers block calls to local server select { case lm := <-h.chLocalProcess: h.localProcess(lm.agent, lm.route, lm.msg) + case rm := <-h.chRemoteProcess: h.remoteService.remoteProcess(nil, rm.agent, rm.route, rm.msg) @@ -157,7 +159,7 @@ func (h *HandlerService) Handle(conn net.Conn) { logger.Log.Debugf("New session established: %s", a.String()) - // guarantee agent related resource be destroyed + // guarantee agent related resource is destroyed defer func() { a.Session.Close() logger.Log.Debugf("Session read goroutine exit, SessionID=%d, UID=%d", a.Session.ID(), a.Session.UID()) @@ -172,7 +174,7 @@ func (h *HandlerService) Handle(conn net.Conn) { return } - // (warning): decoder use slice for performance, packet data should be copy before next Decode + // (warning): decoder uses slice for performance, packet data should be copied before next Decode packets, err := h.decoder.Decode(buf[:n]) if err != nil { logger.Log.Error(err.Error()) @@ -209,7 +211,7 @@ func (h *HandlerService) processPacket(a *agent.Agent, p *packet.Packet) error { case packet.Data: if a.GetStatus() < constants.StatusWorking { - return fmt.Errorf("receive data on socket which not yet ACK, session will be closed immediately, remote=%s", + return fmt.Errorf("receive data on socket which is not yet ACK, session will be closed immediately, remote=%s", a.RemoteAddr().String()) } diff --git a/service/util.go b/service/util.go index 85e5539e..a8c3971b 100644 --- a/service/util.go +++ b/service/util.go @@ -185,7 +185,7 @@ func processHandlerMessage( // This is a special case and should only happen with nats rpc client // because we used nats request we have to answer to it or else a timeout // will happen in the caller server and will be returned to the client - // the reason why we not just Publish is to keep track of failed rpc requests + // the reason why we don't just Publish is to keep track of failed rpc requests // with timeouts, maybe we can improve this flow resp = []byte("ack") }