diff --git a/src/conetty/queued_writer.rs b/src/conetty/queued_writer.rs index 656acd4..69cc3b9 100644 --- a/src/conetty/queued_writer.rs +++ b/src/conetty/queued_writer.rs @@ -18,6 +18,13 @@ impl BufWriter { buf: BytesMut::with_capacity(1024 * 32), } } + #[inline] + fn reserve_buf(&mut self) { + let remain = self.buf.capacity() - self.buf.len(); + if remain < 1024 { + self.buf.reserve(1024 * 32 - remain); + } + } #[inline] fn put_data(&mut self, data: &[u8]) { @@ -59,6 +66,7 @@ impl QueuedWriter { // and the next writer would try to acquire the lock // this only relax the write lock contention let mut writer = self.writer.lock().unwrap(); + writer.reserve_buf(); loop { let mut cnt = 0;