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 Alex Vulaj
parent cf50a3efbb
commit d15aba1e61
1 changed files with 9 additions and 4 deletions

13
conn.go
View File

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