This commit is contained in:
laodaming 2023-08-18 11:05:18 +08:00
parent 37d32a26ab
commit 530d711f75

View File

@ -36,11 +36,24 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) {
publicMutex.Lock() publicMutex.Lock()
defer publicMutex.Unlock() defer publicMutex.Unlock()
//存在是不能给他申请重新绑定 //存在是不能给他申请重新绑定
if _, ok := mapConnPool.Load(clientId); ok { if v, ok := mapConnPool.Load(clientId); ok {
obj, ok := v.(wsConnectItem)
if !ok {
logx.Error("连接断言失败")
}
//是当前自己占用
if obj.uniqueId == w.uniqueId {
//重新绑定
w.uniqueId = clientId
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId)
w.sendToOutChan(rsp)
return
} else {
rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ") rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ")
w.sendToOutChan(rsp) w.sendToOutChan(rsp)
return return
} }
}
//重新绑定 //重新绑定
w.uniqueId = clientId w.uniqueId = clientId
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId) rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId)