From 3dc7dc4fdd66c3ce5dd1445b976f68c0a893ba8d Mon Sep 17 00:00:00 2001 From: wdvxdr Date: Sun, 20 Mar 2022 13:55:08 +0800 Subject: [PATCH] client: use buffered channel this channel use receive with timeout, so we need use buffered to avoid memory leak. --- client/client.go | 2 +- client/network.go | 2 +- client/richmsg.go | 2 +- client/sync.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/client.go b/client/client.go index fb1decd9..430cb000 100644 --- a/client/client.go +++ b/client/client.go @@ -434,7 +434,7 @@ func (c *QQClient) init(tokenLogin bool) error { return errors.Wrap(err, "register error") } if tokenLogin { - notify := make(chan struct{}) + notify := make(chan struct{}, 2) d := c.waitPacket("StatSvc.ReqMSFOffline", func(i any, err error) { notify <- struct{}{} }) diff --git a/client/network.go b/client/network.go index f1adba6f..9fab6e76 100644 --- a/client/network.go +++ b/client/network.go @@ -214,7 +214,7 @@ func (c *QQClient) waitPacket(cmd string, f func(any, error)) func() { // waitPacketTimeoutSyncF // 等待一个数据包解析, 优先级低于 sendAndWait func (c *QQClient) waitPacketTimeoutSyncF(cmd string, timeout time.Duration, filter func(any) bool) (r any, e error) { - notifyChan := make(chan bool) + notifyChan := make(chan bool, 4) defer c.waitPacket(cmd, func(i any, err error) { if filter(i) { r = i diff --git a/client/richmsg.go b/client/richmsg.go index efa3ba69..88356aaf 100644 --- a/client/richmsg.go +++ b/client/richmsg.go @@ -66,7 +66,7 @@ var musicType = [...]musicTypeInfo{ // SendGroupMusicShare 发送群聊音乐卡片 func (c *QQClient) SendGroupMusicShare(target int64, msg *message.MusicShareElement) (*message.GroupMessage, error) { - ch := make(chan *message.GroupMessage) + ch := make(chan *message.GroupMessage, 2) eid := utils.RandomString(6) c.onGroupMessageReceipt(eid, func(c *QQClient, e *groupMessageReceiptEvent) { for _, elem := range e.Msg.Elements { diff --git a/client/sync.go b/client/sync.go index 6f14a4c1..2a75a986 100644 --- a/client/sync.go +++ b/client/sync.go @@ -77,7 +77,7 @@ func (c *QQClient) RefreshStatus() error { // SyncSessions 同步会话列表 func (c *QQClient) SyncSessions() (*SessionSyncResponse, error) { ret := &SessionSyncResponse{} - notifyChan := make(chan bool) + notifyChan := make(chan bool, 4) var groupNum int32 = -1 stop := c.waitPacket("RegPrxySvc.PbSyncMsg", func(i any, err error) { if err != nil {