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

@@ -120,7 +120,7 @@ type TcpClient struct {
Clients map[string]*PrintInfo //放tcp连接的printNo 为key
MsgMap map[string]chan *model.PrintMsg //放打印信息的printNo为key
CallBackMap map[string]chan string //放打印信息回调信息的printNo为key
TimeoutChan chan bool //退出channel
TimeoutMap map[string]chan bool //退出channel
*sync.RWMutex
}
@@ -149,9 +149,6 @@ func (t *TcpClient) addConn(c net.Conn, key string, status int) {
Status: status,
StatusTime: time.Now(),
}
if t.TimeoutChan == nil {
t.TimeoutChan = make(chan bool)
}
}
func (t *TcpClient) buildMsgMap(key string) {
@@ -168,6 +165,13 @@ func (t *TcpClient) buildCallBackMap(key string) {
t.CallBackMap[key] = dataChan
}
func (t *TcpClient) buildTimeoutMap(key string) {
t.Lock()
defer t.Unlock()
dataChan := make(chan bool)
t.TimeoutMap[key] = dataChan
}
func (t *TcpClient) getPrintStatus(key string) int {
t.RLock()
defer t.RUnlock()
@@ -283,7 +287,7 @@ func NewTcpClient() *TcpClient {
Clients: make(map[string]*PrintInfo),
CallBackMap: make(map[string]chan string),
MsgMap: make(map[string]chan *model.PrintMsg),
TimeoutChan: make(chan bool),
TimeoutMap: make(map[string]chan bool),
}
t.RWMutex = new(sync.RWMutex)
return t