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