This commit is contained in:
suyl
2021-07-29 18:25:00 +08:00
parent b18672e92d
commit 37440aa104
2 changed files with 12 additions and 4 deletions

View File

@@ -92,7 +92,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
//t.Lock()
//t.Clients[printNo] = printInfo
//t.Unlock()
t.addConn(c, printNo, printStatus2JxStatus(data[len(data)-8:len(data)-6]))
t.addConn(c, printNo, status)
t.buildCallBackMap(printNo)
changePrinterStatus(printNo, status)
if status == printerStatusOnline {
@@ -298,10 +298,14 @@ func (t *TcpClient) doPrint2(printMsgChan chan *model.PrintMsg) (err error) {
dao.UpdateEntity(db, printMsg, "Status", "Comment")
if t.CallBackMap[printMsg.PrintNo] != nil {
t.RLock()
dataStr := <-t.CallBackMap[printMsg.PrintNo]
select {
case dataStr := <-t.CallBackMap[printMsg.PrintNo]:
a, b := getCallbackMsgInfo(dataStr)
t.changePrintMsg(dataStr, a, b)
case <-timeoutChan:
}
t.RUnlock()
a, b := getCallbackMsgInfo(dataStr)
t.changePrintMsg(dataStr, a, b)
}
//dataStr := <-printMsgCallbackChan
}

View File

@@ -102,6 +102,7 @@ var (
printMsgChan = make(chan *model.PrintMsg, 1024)
//printMsgCallbackMap = make(map[string]chan string, 1024)
printMsgChanFail = make(chan *model.PrintMsg, 1024)
timeoutChan = make(chan int, 10)
)
type PrintInfo struct {
@@ -144,8 +145,11 @@ func (t *TcpClient) addConn(c net.Conn, key string, status int) {
}
func (t *TcpClient) buildCallBackMap(key string) {
t.Lock()
defer t.Unlock()
dataChan := make(chan string, 1024)
t.CallBackMap[key] = dataChan
timeoutChan <- 1
}
func (t *TcpClient) getPrintStatus(key string) int {