fix
This commit is contained in:
parent
57c61e5921
commit
6c3344b127
|
@ -64,8 +64,6 @@ var (
|
||||||
}
|
}
|
||||||
//websocket连接存储
|
//websocket连接存储
|
||||||
mapConnPool = sync.Map{}
|
mapConnPool = sync.Map{}
|
||||||
//公共互斥锁(复用连接标识用)
|
|
||||||
publicMutex sync.Mutex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 每个连接的连接基本属性
|
// 每个连接的连接基本属性
|
||||||
|
@ -140,8 +138,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
// 设置连接
|
// 设置连接
|
||||||
func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) {
|
func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) {
|
||||||
publicMutex.Lock()
|
|
||||||
defer publicMutex.Unlock()
|
|
||||||
//生成连接唯一标识
|
//生成连接唯一标识
|
||||||
uniqueId, err := l.getUniqueId(userInfo)
|
uniqueId, err := l.getUniqueId(userInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -37,20 +37,14 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) {
|
||||||
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "the client id is not belong you before"))
|
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "the client id is not belong you before"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
publicMutex.Lock()
|
|
||||||
defer publicMutex.Unlock()
|
|
||||||
//存在是不能给他申请重新绑定
|
//存在是不能给他申请重新绑定
|
||||||
if v, ok := mapConnPool.Load(clientId); ok {
|
if v, ok := mapConnPool.Load(clientId); ok {
|
||||||
obj, ok := v.(wsConnectItem)
|
obj, ok := v.(wsConnectItem)
|
||||||
if !ok {
|
if !ok {
|
||||||
logx.Error("连接断言失败")
|
logx.Error("连接断言失败")
|
||||||
}
|
}
|
||||||
//是当前自己占用
|
//是当前自己占用(无需处理)
|
||||||
if obj.uniqueId == w.uniqueId {
|
if obj.uniqueId == w.uniqueId {
|
||||||
//重新绑定
|
|
||||||
w.uniqueId = clientId
|
|
||||||
rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId)
|
|
||||||
w.sendToOutChan(rsp)
|
|
||||||
return
|
return
|
||||||
} else {
|
} 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 ")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user