11
This commit is contained in:
parent
67fe103ac1
commit
7fa7b868ca
|
@ -81,12 +81,12 @@ var (
|
|||
|
||||
// 用户标识的连接增删操作队列传输的值的结构
|
||||
type userConnPoolCtlChanItem struct {
|
||||
userId int64 //必须(两个用户id任意一个不为0)
|
||||
guestId int64 //必须(两个用户id任意一个不为0)
|
||||
uniqueId string //主连接池唯一标识(添加/删除时候必须)
|
||||
message []byte //消息(发送消息传的,格式是经过标准输出序列化后的数据)
|
||||
messageType constants.Websocket //消息类型(发送消息传的)
|
||||
option int64 //操作 2发消息 1增加 0删除
|
||||
userId int64 //必须(两个用户id任意一个不为0)
|
||||
guestId int64 //必须(两个用户id任意一个不为0)
|
||||
uniqueId string //主连接池唯一标识(添加/删除时候必须)
|
||||
message []byte //消息(发送消息传的,格式是经过标准输出序列化后的数据)
|
||||
//messageType constants.Websocket //消息类型(发送消息传的)
|
||||
option int64 //操作 2发消息 1增加 0删除
|
||||
}
|
||||
|
||||
// 每个连接的连接基本属性
|
||||
|
|
|
@ -19,12 +19,11 @@ func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
|||
return
|
||||
}
|
||||
data := userConnPoolCtlChanItem{
|
||||
userId: userId,
|
||||
guestId: guestId,
|
||||
uniqueId: uniqueId,
|
||||
message: nil,
|
||||
messageType: "",
|
||||
option: 1,
|
||||
userId: userId,
|
||||
guestId: guestId,
|
||||
uniqueId: uniqueId,
|
||||
message: nil,
|
||||
option: 1,
|
||||
}
|
||||
select {
|
||||
case userConnPoolCtlChan <- data:
|
||||
|
@ -38,17 +37,13 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
|
|||
return
|
||||
}
|
||||
data := userConnPoolCtlChanItem{
|
||||
userId: userId,
|
||||
guestId: guestId,
|
||||
uniqueId: uniqueId,
|
||||
message: nil,
|
||||
messageType: "",
|
||||
option: 0,
|
||||
}
|
||||
select {
|
||||
case userConnPoolCtlChan <- data:
|
||||
return
|
||||
userId: userId,
|
||||
guestId: guestId,
|
||||
uniqueId: uniqueId,
|
||||
message: nil,
|
||||
option: 0,
|
||||
}
|
||||
userConnPoolCtlChan <- data
|
||||
}
|
||||
|
||||
// 根据用户索引发现链接并发送(广播)消息到出口队列
|
||||
|
@ -89,7 +84,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
|
|||
userKey = getmapUserConnPoolUniqueId(data.userId, data.guestId)
|
||||
switch data.option {
|
||||
case 2: //发送消息
|
||||
logx.Info("通过用户id索引发送消息")
|
||||
//logx.Info("通过用户id索引发送消息")
|
||||
mapUserUniqueId, ok := mapUserConnPool[userKey]
|
||||
if !ok {
|
||||
logx.Info("通过用户id索引发送消息,连接不存在,用户索引key:", userKey)
|
||||
|
@ -110,7 +105,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
|
|||
originConn.sendToOutChan(data.message)
|
||||
}
|
||||
case 1: //添加
|
||||
logx.Info("添加用户id索引标识:", data.uniqueId)
|
||||
//logx.Info("添加用户id索引标识:", data.uniqueId)
|
||||
//存在这个用户的map池子
|
||||
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
|
||||
mapUserUniqueId[data.uniqueId] = struct{}{}
|
||||
|
@ -119,7 +114,7 @@ func ConsumeUserConnPoolCtlChanData(ctx context.Context) {
|
|||
mapUserConnPool[userKey][data.uniqueId] = struct{}{}
|
||||
}
|
||||
case 0: //删除
|
||||
logx.Info("删除用户id索引标识:", data.uniqueId)
|
||||
//logx.Info("删除用户id索引标识:", data.uniqueId)
|
||||
if mapUserUniqueId, ok := mapUserConnPool[userKey]; ok {
|
||||
delete(mapUserUniqueId, data.uniqueId)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user