This commit is contained in:
suyl
2021-08-03 14:51:27 +08:00
parent 7a6f3b20d7
commit aeee9731cd

View File

@@ -199,8 +199,9 @@ func (t *TcpClient) doPrint(key string) (err error) {
globals.SugarLogger.Debugf("doPrint timeout") globals.SugarLogger.Debugf("doPrint timeout")
return return
default: default:
printMsg, ok := <-t.MsgMap[key] select {
if !ok { case printMsg, ok := <-t.MsgMap[key]:
if !ok{
return return
} }
var ( var (
@@ -230,19 +231,15 @@ func (t *TcpClient) doPrint(key string) (err error) {
printMsg.Status = printMsgErr printMsg.Status = printMsgErr
printMsg.Comment = err.Error() printMsg.Comment = err.Error()
dao.UpdateEntity(db, printMsg, "Status", "Comment") dao.UpdateEntity(db, printMsg, "Status", "Comment")
if t.isExist(key) { close(t.TimeoutMap[key])
t.clear(key)
globals.SugarLogger.Debugf("handleTcpMessages clear1...") globals.SugarLogger.Debugf("handleTcpMessages clear1...")
}
} else { } else {
if c != nil { if c != nil {
if _, err = c.Write(data); err != nil { if _, err = c.Write(data); err != nil {
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err) globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
//t.delConn(printMsg.PrintNo) //t.delConn(printMsg.PrintNo)
if t.isExist(key) { close(t.TimeoutMap[key])
t.clear(key)
globals.SugarLogger.Debugf("handleTcpMessages clear2...") globals.SugarLogger.Debugf("handleTcpMessages clear2...")
}
} else { } else {
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data)) globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
//等待回调 //等待回调
@@ -255,7 +252,10 @@ func (t *TcpClient) doPrint(key string) (err error) {
} }
} }
} }
}
}() }()
close(t.MsgMap[key])
close(t.CallBackMap[key])
return err return err
} }
@@ -273,14 +273,12 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
//2分钟内没心跳判断打印机掉线了 //2分钟内没心跳判断打印机掉线了
if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute+time.Second*3 { if time.Now().Sub(t.getPrintStatusTime(key)) > time.Minute+time.Second*3 {
changePrinterStatus(key, printerStatusOffline) changePrinterStatus(key, printerStatusOffline)
if t.isExist(key) {
globals.SugarLogger.Debugf("HandleCheckTcpHeart clear...") globals.SugarLogger.Debugf("HandleCheckTcpHeart clear...")
//t.clear(key) //t.clear(key)
close(t.TimeoutMap[key]) close(t.TimeoutMap[key])
} }
} }
} }
}
//keys := []string{} //keys := []string{}
//t.RLock() //t.RLock()
//for k, v := range t.Clients { //for k, v := range t.Clients {
@@ -299,4 +297,5 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
//} //}
} }
}() }()
t.Clients[key].C.Close()
} }