From 4f1965c93d62d3c5272dfdaf68c02549e26a5dad Mon Sep 17 00:00:00 2001 From: guonaihong Date: Sun, 13 Aug 2023 12:37:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8B=E9=94=81=E7=9A=84?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4=E8=8C=83=E5=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conn.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/conn.go b/conn.go index e93bfc8..d92dceb 100644 --- a/conn.go +++ b/conn.go @@ -569,19 +569,19 @@ func (c *Conn) WriteMessageDelay(op Opcode, writeBuf []byte) (err error) { writeBuf = out.Bytes() } + c.delayMu.Lock() // 初始化缓存 if c.delayBuf == nil && c.delayWriteInitBufferSize > 0 { - c.delayMu.Lock() // TODO sync.Pool管理下, 如果size是1k 2k 3k delayBuf := make([]byte, 0, c.delayWriteInitBufferSize) c.delayBuf = bytes.NewBuffer(delayBuf) - c.delayMu.Unlock() } // 初始化定时器 if c.delayTimeout == nil && c.maxDelayWriteDuration > 0 { c.delayTimeout = time.AfterFunc(c.maxDelayWriteDuration, c.writerDelayBufSafe) } + c.delayMu.Unlock() maskValue := uint32(0) if c.client { @@ -595,12 +595,9 @@ func (c *Conn) WriteMessageDelay(op Opcode, writeBuf []byte) (err error) { c.delayMu.Unlock() return err } - c.delayMu.Unlock() - // go func() { - // 为了平衡生产者,消费者的速度,这里不再使用协程 + // 为了平衡生产者,消费者的速度,这里不使用协程 - c.delayMu.Lock() if c.delayBuf != nil { frame.WriteFrameToBytes(c.delayBuf, writeBuf, true, rsv1, c.client, op, maskValue) }