ringbuffer: force size to be a power of 2

otherwise buffer is used partially when writeIndex overflows.
This commit is contained in:
aler9
2022-07-05 19:25:53 +02:00
parent ef900359ce
commit 18005a9cde
6 changed files with 41 additions and 18 deletions

View File

@@ -169,6 +169,9 @@ func (s *Server) Start() error {
if s.WriteBufferCount == 0 {
s.WriteBufferCount = 256
}
if (s.WriteBufferCount & (s.WriteBufferCount - 1)) != 0 {
return fmt.Errorf("WriteBufferCount must be a power of two")
}
// system functions
if s.Listen == nil {