This commit is contained in:
suyl
2021-07-30 10:49:44 +08:00
parent cceb2db107
commit e092178d32
2 changed files with 18 additions and 21 deletions

View File

@@ -114,7 +114,7 @@ type PrintInfo struct {
//连接的客户端,吧每个客户端都放进来
type TcpClient struct {
Clients map[string]*PrintInfo
CallBackMap sync.Map
CallBackMap map[string]chan string
*sync.RWMutex
}
@@ -145,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.Store(key, dataChan)
t.CallBackMap[key] = dataChan
timeoutChan <- 1
}
func (t *TcpClient) getPrintStatus(key string) int {
@@ -192,8 +195,8 @@ func (t *TcpClient) setPrintStatus(key string, status int) {
func NewTcpClient() *TcpClient {
t := &TcpClient{
Clients: make(map[string]*PrintInfo),
//CallBackMap: new(sync.Map),
Clients: make(map[string]*PrintInfo),
CallBackMap: make(map[string]chan string),
}
t.RWMutex = new(sync.RWMutex)
return t