This commit is contained in:
suyl
2021-07-30 10:05:25 +08:00
parent 59d71369a9
commit cceb2db107
2 changed files with 23 additions and 21 deletions

View File

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