Fix buffer remaining capacity calcualtion

This commit is contained in:
Nikolay Kim 2019-12-09 21:44:26 +06:00
parent 0c1f5f9edc
commit 5132257b0d
3 changed files with 12 additions and 7 deletions

View file

@ -8,7 +8,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Decoder, Encoder, Framed, FramedParts};
use actix_rt::time::{delay_until, Delay, Instant};
use actix_service::Service;
use bitflags::bitflags;
use bytes::{BufMut, BytesMut};
use bytes::BytesMut;
use log::{error, trace};
use crate::body::{Body, BodySize, MessageBody, ResponseBody};
@ -751,8 +751,10 @@ where
};
loop {
if inner.write_buf.remaining_mut() < LW_BUFFER_SIZE {
inner.write_buf.reserve(HW_BUFFER_SIZE);
let remaining =
inner.write_buf.capacity() - inner.write_buf.len();
if remaining < LW_BUFFER_SIZE {
inner.write_buf.reserve(HW_BUFFER_SIZE - remaining);
}
let result = inner.poll_response(cx)?;
let drain = result == PollResponse::DrainWriteBuf;
@ -863,8 +865,9 @@ where
{
let mut read_some = false;
loop {
if buf.remaining_mut() < LW_BUFFER_SIZE {
buf.reserve(HW_BUFFER_SIZE);
let remaining = buf.capacity() - buf.len();
if remaining < LW_BUFFER_SIZE {
buf.reserve(HW_BUFFER_SIZE - remaining);
}
match read(cx, io, buf) {