aa
This commit is contained in:
@@ -84,9 +84,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
|
||||
globals.SugarLogger.Debugf("handleConn clients map: %v", t.Clients)
|
||||
if t.Clients[printNo] == nil {
|
||||
t.addConn(c, printNo, status)
|
||||
t.buildCallBackMap(printNo)
|
||||
t.buildMsgMap(printNo)
|
||||
t.buildTimeoutMap(printNo)
|
||||
t.buildAllMap(printNo)
|
||||
t.HandleTcpMessages(printNo)
|
||||
t.doPrint(printNo)
|
||||
if status == printerStatusOnline {
|
||||
@@ -239,7 +237,6 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
t.clear(key)
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear1...")
|
||||
}
|
||||
return
|
||||
} else {
|
||||
if c != nil {
|
||||
if _, err = c.Write(data); err != nil {
|
||||
@@ -249,7 +246,6 @@ func (t *TcpClient) doPrint(key string) (err error) {
|
||||
t.clear(key)
|
||||
globals.SugarLogger.Debugf("handleTcpMessages clear2...")
|
||||
}
|
||||
return
|
||||
} else {
|
||||
globals.SugarLogger.Debugf("handleTcpMessages success, data: %v", hex.EncodeToString(data))
|
||||
//等待回调
|
||||
@@ -284,7 +280,6 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
|
||||
t.clear(key)
|
||||
globals.SugarLogger.Debugf("HandleCheckTcpHeart clear...")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,14 @@ func (t *TcpClient) buildTimeoutMap(key string) {
|
||||
t.TimeoutMap[key] = dataChan
|
||||
}
|
||||
|
||||
func (t *TcpClient) buildAllMap(key string) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
t.MsgMap[key] = make(chan *model.PrintMsg, 1024)
|
||||
t.CallBackMap[key] = make(chan string, 1024)
|
||||
t.TimeoutMap[key] = make(chan bool)
|
||||
}
|
||||
|
||||
func (t *TcpClient) getPrintStatus(key string) int {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
@@ -275,11 +283,11 @@ func (t *TcpClient) clear(key string) {
|
||||
t.Lock()
|
||||
defer t.Unlock()
|
||||
t.Clients[key].C.Close()
|
||||
delete(t.Clients, key)
|
||||
close(t.MsgMap[key])
|
||||
delete(t.MsgMap, key)
|
||||
close(t.CallBackMap[key])
|
||||
delete(t.CallBackMap, key)
|
||||
//delete(t.Clients, key)
|
||||
//close(t.MsgMap[key])
|
||||
//delete(t.MsgMap, key)
|
||||
//close(t.CallBackMap[key])
|
||||
//delete(t.CallBackMap, key)
|
||||
close(t.TimeoutMap[key])
|
||||
delete(t.TimeoutMap, key)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user