1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-22 21:55:10 +02:00

properly allocate read buffer

This commit is contained in:
Nikolay Kim
2019-04-02 11:11:32 -07:00
parent d067b1d5f1
commit 49a499ce74
3 changed files with 23 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
//! HTTP/1 implementation
use bytes::Bytes;
use bytes::{Bytes, BytesMut};
mod client;
mod codec;
@@ -38,6 +38,16 @@ pub enum MessageType {
Stream,
}
const LW: usize = 2 * 1024;
const HW: usize = 32 * 1024;
pub(crate) fn reserve_readbuf(src: &mut BytesMut) {
let cap = src.capacity();
if cap < LW {
src.reserve(HW - cap);
}
}
#[cfg(test)]
mod tests {
use super::*;