This commit is contained in:
suyl
2021-08-03 11:26:45 +08:00
parent b3e86e8e63
commit 8e44870cbf
2 changed files with 16 additions and 11 deletions

View File

@@ -83,6 +83,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
t.addConn(c, printNo, status)
t.buildCallBackMap(printNo)
t.buildMsgMap(printNo)
t.buildTimeoutMap(printNo)
t.HandleTcpMessages(printNo)
t.doPrint(printNo)
if status == printerStatusOnline {
@@ -167,7 +168,7 @@ func (t *TcpClient) HandleTcpMessages(printNo string) {
go func() {
for {
select {
case <-t.TimeoutChan:
case <-t.TimeoutMap[printNo]:
globals.SugarLogger.Debugf("HandleTcpMessages timeout")
return
default:
@@ -196,7 +197,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
go func() {
for {
select {
case <-t.TimeoutChan:
case <-t.TimeoutMap[key]:
globals.SugarLogger.Debugf("doPrint timeout")
return
default:
@@ -233,7 +234,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
dao.UpdateEntity(db, printMsg, "Status", "Comment")
if t.isExist(key) {
t.clear(key)
close(t.TimeoutChan)
close(t.TimeoutMap[key])
}
return
} else {
@@ -243,7 +244,7 @@ func (t *TcpClient) doPrint(key string) (err error) {
//t.delConn(printMsg.PrintNo)
if t.isExist(key) {
t.clear(key)
close(t.TimeoutChan)
close(t.TimeoutMap[key])
}
} else {
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
@@ -267,7 +268,7 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
go func() {
for {
select {
case <-t.TimeoutChan:
case <-t.TimeoutMap[key]:
globals.SugarLogger.Debugf("HandleCheckTcpHeart timeout")
return
default:
@@ -277,7 +278,7 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
changePrinterStatus(key, printerStatusOffline)
if t.isExist(key) {
t.clear(key)
close(t.TimeoutChan)
close(t.TimeoutMap[key])
return
}
}