This commit is contained in:
邹宗楠
2022-12-29 16:25:18 +08:00
parent 22e81eb28a
commit 96129c6e31
2 changed files with 9 additions and 2 deletions

View File

@@ -69,7 +69,7 @@ func (t *TcpClient) handleConn(c net.Conn) {
//5、修改数据库中打印机状态没在连接池中说明是重新连接的 //5、修改数据库中打印机状态没在连接池中说明是重新连接的
//6、监听心跳时间超过1分多钟就clear掉 //6、监听心跳时间超过1分多钟就clear掉
//globals.SugarLogger.Debugf("handleConn timeout channel...: %v", t.TimeoutMap[printNo]) //globals.SugarLogger.Debugf("handleConn timeout channel...: %v", t.TimeoutMap[printNo])
if t.Clients[printNo] == nil { if t.getClients(printNo) == nil {
t.addConn(c, printNo, status) t.addConn(c, printNo, status)
t.buildAllMap(printNo) t.buildAllMap(printNo)
t.HandleTcpMessages(printNo) t.HandleTcpMessages(printNo)
@@ -314,7 +314,7 @@ func (t *TcpClient) HandleCheckTcpHeart(key string) {
for { for {
select { select {
case <-t.TimeoutMap[key]: case <-t.TimeoutMap[key]:
t.Clients[key].C.Close() t.getClients(key).C.Close()
close(t.MsgMap[key]) close(t.MsgMap[key])
close(t.CallBackMap[key]) close(t.CallBackMap[key])
delete(t.Clients, key) delete(t.Clients, key)

View File

@@ -219,6 +219,13 @@ func (t *TcpClient) getPrintStatusTime(key string) time.Time {
} }
} }
// 获取连接对象
func (t *TcpClient) getClients(key string) *PrintInfo {
t.RLock()
defer t.RUnlock()
return t.Clients[key]
}
func (t *TcpClient) isExistMsg(key string) bool { func (t *TcpClient) isExistMsg(key string) bool {
t.RLock() t.RLock()
defer t.RUnlock() defer t.RUnlock()