perf: reduce timer in write_control

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
This commit is contained in:
rfyiamcool 2023-12-08 17:24:58 +08:00 committed by Canelo Hill
parent 1d5465562b
commit d1c25593b9
1 changed files with 9 additions and 4 deletions

View File

@ -443,6 +443,9 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
}
}
select {
case <-c.mu:
default:
timer := time.NewTimer(d)
select {
case <-c.mu:
@ -450,6 +453,8 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
case <-timer.C:
return errWriteTimeout
}
}
defer func() { c.mu <- struct{}{} }()
c.writeErrMu.Lock()