From b3bc7a22c4a43036e1853dedf41fb03bbe6fce70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 20 Dec 2022 16:26:39 +0800 Subject: [PATCH] 1' --- business/jxstore/event/event_tcp.go | 10 +++------- business/jxstore/event/event_tcp_utils.go | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index f152fa00a..15057866b 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -168,10 +168,7 @@ func (t *TcpClient) HandleTcpMessages(printNo string) { go func() { for { - //if time.Now().Second()%2 != 0 { - // continue - //} - time.Sleep(1 * time.Second) + select { case <-t.TimeoutMap[printNo]: globals.SugarLogger.Debugf("HandleTcpMessages timeout") @@ -205,6 +202,7 @@ func (t *TcpClient) doPrint(key string) (err error) { var ( db = dao.GetDB() ) + if !t.isExistMsg(key) { return err } @@ -226,8 +224,6 @@ func (t *TcpClient) doPrint(key string) (err error) { c net.Conn ) if printMsg != nil { - time.Sleep(2 * time.Second) - globals.SugarLogger.Debugf("printMsg ... %s", utils.Format4Output(printMsg, false)) if err = checkPrintMsg(db, printMsg); err == nil { status := t.getPrintStatus(printMsg.PrintNo) switch status { @@ -265,7 +261,7 @@ func (t *TcpClient) doPrint(key string) (err error) { close(t.TimeoutMap[key]) } else { //等待回调 - dataStr := <-t.CallBackMap[printMsg.PrintNo] + dataStr := t.GetCallbackChan(printMsg.PrintNo) if dataStr != "" { a, b := getCallbackMsgInfo(dataStr) t.changePrintMsg(dataStr, a, b) diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index b1c914783..492d71786 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -293,6 +293,15 @@ func (t *TcpClient) addCallbackChan(key, data string) { t.CallBackMap[key] <- data } +func (t *TcpClient) GetCallbackChan(key string) string { + t.RLock() + defer t.RUnlock() + if t.CallBackMap[key] == nil { + return "" + } + return <-t.CallBackMap[key] +} + func (t *TcpClient) clear(key string) { t.Lock() defer t.Unlock()