修复锁问题

pull/23/head
630892807@qq.com 4 years ago
parent c3d4e6e1f9
commit 77ba60717a

@ -91,8 +91,8 @@ func OneKefuMessage(toId string, str []byte) {
if mKefuConns != nil && ok {
for _, kefu := range mKefuConns {
log.Println("OneKefuMessage lock")
Mux.Lock()
defer Mux.Unlock()
kefu.Mux.Lock()
defer kefu.Mux.Unlock()
log.Println("OneKefuMessage unlock")
kefu.Conn.WriteMessage(websocket.TextMessage, str)
}
@ -113,6 +113,8 @@ func SendPingToKefuClient() {
if kefuConn == nil {
continue
}
kefuConn.Mux.Lock()
defer kefuConn.Mux.Unlock()
err := kefuConn.Conn.WriteMessage(websocket.TextMessage, str)
if err == nil {
newKefuConns = append(newKefuConns, kefuConn)

@ -21,12 +21,14 @@ type User struct {
Avator string
To_id string
Role_id string
Mux sync.Mutex
}
type Message struct {
conn *websocket.Conn
context *gin.Context
content []byte
messageType int
Mux sync.Mutex
}
type TypeMessage struct {
Type interface{} `json:"type"`
@ -126,9 +128,9 @@ func WsServerBackend() {
Type: "pong",
}
str, _ := json.Marshal(msg)
Mux.Lock()
message.Mux.Lock()
defer message.Mux.Unlock()
conn.WriteMessage(websocket.TextMessage, str)
Mux.Unlock()
case "inputing":
to := typeMsg.Data.(map[string]interface{})["to"].(string)
OneKefuMessage(to, message.content)

Loading…
Cancel
Save