From b87b12f5489f8834de1c8d52ccf679cae89cffd5 Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Mon, 2 Aug 2021 17:24:54 +0800 Subject: [PATCH] aa --- business/jxstore/event/event_tcp.go | 32 ++++++++++++++++------- business/jxstore/event/event_tcp_utils.go | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/business/jxstore/event/event_tcp.go b/business/jxstore/event/event_tcp.go index b53afd65d..c6daf0b59 100644 --- a/business/jxstore/event/event_tcp.go +++ b/business/jxstore/event/event_tcp.go @@ -228,6 +228,13 @@ func (t *TcpClient) doPrint(key string) (err error) { printMsg.Status = printMsgErr printMsg.Comment = err.Error() dao.UpdateEntity(db, printMsg, "Status", "Comment") + if t.isExist(key) { + timeoutChan <- 1 + timeoutChan <- 1 + timeoutChan <- 1 + t.clear(key) + } + return } else { if c != nil { if _, err = c.Write(data); err != nil { @@ -253,16 +260,21 @@ func (t *TcpClient) doPrint(key string) (err error) { func (t *TcpClient) HandleCheckTcpHeart(key string) { go func() { for { - if !utils.IsTimeZero(t.getPrintStatusTime(key)) { - //2分钟内没心跳判断打印机掉线了 - if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute*2 { - changePrinterStatus(key, printerStatusOffline) - if t.isExist(key) { - globals.SugarLogger.Debugf("HandleCheckTcpHeart del key,%v", key) - timeoutChan <- 1 - timeoutChan <- 1 - t.clear(key) - return + select { + case <-timeoutChan: + return + default: + if !utils.IsTimeZero(t.getPrintStatusTime(key)) { + //2分钟内没心跳判断打印机掉线了 + if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute*2 { + changePrinterStatus(key, printerStatusOffline) + if t.isExist(key) { + timeoutChan <- 1 + timeoutChan <- 1 + timeoutChan <- 1 + t.clear(key) + return + } } } } diff --git a/business/jxstore/event/event_tcp_utils.go b/business/jxstore/event/event_tcp_utils.go index 9f1e4ecd1..6bf53f44b 100644 --- a/business/jxstore/event/event_tcp_utils.go +++ b/business/jxstore/event/event_tcp_utils.go @@ -108,7 +108,7 @@ var ( regexpQrr = regexp.MustCompile(byteSignQrRight + "(.*?)" + byteSignQrRightE) regexpSound = regexp.MustCompile(byteSignSound + "(.*?)" + byteSignSoundE) - timeoutChan = make(chan int, 2) + timeoutChan = make(chan int, 3) ) type PrintInfo struct {