From e775d55e2ea07b97db1a77d43c6e4b699e912ac1 Mon Sep 17 00:00:00 2001 From: shoopea Date: Wed, 31 Jul 2019 14:19:09 +0800 Subject: [PATCH] client revamp compilation fix --- bot.go | 18 +++++++++--------- client.go | 8 ++++++-- workers.go | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bot.go b/bot.go index 8e69a9f..9e76916 100644 --- a/bot.go +++ b/bot.go @@ -166,7 +166,7 @@ func botGetClients(m *tb.Message) { return } if clt, ok := getLockedClient(m.Chat.ID, false); ok { - clt.Unlock() + clt.Mux.Unlock() muxClients.RLock() var ret string for id, c := range clients { @@ -213,7 +213,7 @@ func botMsgRescan(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -275,7 +275,7 @@ func botMsgRescanAll(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -330,7 +330,7 @@ func botBackupExport(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -368,7 +368,7 @@ func botBackupImport(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -419,7 +419,7 @@ func botMsgDump(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -476,7 +476,7 @@ func botListParsingRules(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -517,7 +517,7 @@ func botListParsingRule(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() if clt.TGUserID64 != cfg.Bot.Admin { c := TGCommand{ Type: commandReplyMsg, @@ -598,7 +598,7 @@ func botTimer(m *tb.Message) { TGCmdQueue <- c return } - clt.Unlock() + clt.Mux.Unlock() r := regexp.MustCompile("^(?P([0-9]*(s|m|h))+) \"(?P(.*))\"$") if r.MatchString(m.Payload) { diff --git a/client.go b/client.go index a0027f9..a2396f8 100644 --- a/client.go +++ b/client.go @@ -9,18 +9,22 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) { muxClients.RLock() if c, ok := clients[id]; ok { c.Mux.Lock() + muxClients.RUnlock() return c, true } else if createMissing { c := new(ChirpClient) - clients[id] = c c.TGUserID64 = id c.Active = false c.Lock() + muxClients.RUnlock() + muxClients.Lock() + clients[id] = c + muxClients.Unlock() return c, true } else { + muxClients.RUnlock() return 0, false } - defer muxClients.RUnlock() } func clientSendCWMsg(userID64 int64, s string) { diff --git a/workers.go b/workers.go index a0eae9a..c7f5a5f 100644 --- a/workers.go +++ b/workers.go @@ -203,7 +203,7 @@ func MQKeepAliveWorker() { } } } - clt.Unlock() + clt.Mux.Unlock() c := TGCommand{ Type: commandSendMsg, @@ -286,7 +286,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) { }) logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Publishing message.") //log.Printf("MQTGCmdWorker[" + strconv.Itoa(id) + "] : Message published.") - clt.Unlock() + clt.Mux.Unlock() } else { log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : client %d offline.\n", c.FromUserID64) }