Commit d3c3d90e authored by haoyanbin's avatar haoyanbin

1

parent 43001efb
......@@ -25,7 +25,7 @@ const (
//
closeWait = 60 * 30 * time.Second
//
// time for auto end
endDate = 60 * 2 * time.Second
)
......@@ -142,7 +142,7 @@ func (c *Client) readPump() {
close(c.sendPing)
c.grpool.Close()
c.hub.RemoveClient(c)
Redis.HDel(cliKey, c.Id)
DelClient(c.Id)
dump()
}()
Loop:
......
......@@ -27,7 +27,7 @@ var (
// clients.
type hub struct {
// Registered clients.
clients map[string]*Client // //新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了
clients map[string]*Client //新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了
oldClients map[string]*Client //缓存断开的连接消息队列
// Inbound messages from the clients.
......
......@@ -28,8 +28,7 @@ func InitWsPool(errfun func(err interface{})) {
}
func initWsPoolData() {
clientsData := Redis.HGetAll(cliKey)
clientsAll := clientsData.Val()
clientsAll := GetAllList(cliKey)
for _, v := range clientsAll {
if v == "" {
......
......@@ -10,8 +10,6 @@ import (
"time"
)
var toConverstaionLock sync.Mutex
type SetMsgReq struct {
ProcedureType int `json:"procedureType"`
GroupId string `json:"groupId" db:"group_id"`
......@@ -78,8 +76,7 @@ func NewClient(conf *Config) *Client {
client.OnPing(nil)
client.OnPong(nil)
wsSever.hub.AddClient(client)
jsonData := string(SerializeJson(conf))
Redis.HSet(cliKey, client.Id, jsonData)
AppendClient(client.Id,string(SerializeJson(conf)))
return client
}
......@@ -509,8 +506,8 @@ func PublishData(mqData *SetMsgReq) {
return
}
func GetConversationList() map[string]string {
jsonData := Redis.HGetAll(convKey)
func GetAllList(key string) map[string]string {
jsonData := Redis.HGetAll(key)
jsonDataAll := jsonData.Val()
return jsonDataAll
}
......@@ -525,8 +522,18 @@ func DelConversation(customerClientId, userClientId string) {
return
}
func AppendClient(clientId, data string){
Redis.HSet(cliKey, clientId, data)
return
}
func DelClient(clientId string) {
Redis.HDel(cliKey, clientId)
return
}
func SetEnd() {
conversationList := GetConversationList()
conversationList := GetAllList(convKey)
for _, vClients := range conversationList {
conversationData := &Conversation{}
UnserislizeJson([]byte(vClients), conversationData)
......
......@@ -164,6 +164,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
pool.PublishData(closeMsg)
fmt.Println("专家关闭连接", client.Id)
}
pool.DelClient(client.Id)
fmt.Printf("连接己经关闭%s", client.Id)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment