1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-24 00:01:11 +01:00

Fix buffer remaining capacity calcualtion

This commit is contained in:
Nikolay Kim 2019-12-09 21:50:36 +06:00
parent 35218a4df1
commit 8b3062cd6e
3 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# Changes # Changes
## [0.2.0-alpha.4]
* Fix buffer remaining capacity calcualtion
## [0.2.0-alpha.3] ## [0.2.0-alpha.3]
* Use tokio 0.2 * Use tokio 0.2

View File

@ -1,6 +1,6 @@
[package] [package]
name = "actix-codec" name = "actix-codec"
version = "0.2.0-alpha.3" version = "0.2.0-alpha.4"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
description = "Utilities for encoding and decoding frames" description = "Utilities for encoding and decoding frames"
keywords = ["network", "framework", "async", "futures"] keywords = ["network", "framework", "async", "futures"]

View File

@ -2,7 +2,7 @@ use std::pin::Pin;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::{fmt, io}; use std::{fmt, io};
use bytes::{BufMut, BytesMut}; use bytes::BytesMut;
use futures::{ready, Sink, Stream}; use futures::{ready, Sink, Stream};
use crate::{AsyncRead, AsyncWrite, Decoder, Encoder}; use crate::{AsyncRead, AsyncWrite, Decoder, Encoder};
@ -208,7 +208,7 @@ impl<T, U> Framed<T, U> {
T: AsyncWrite, T: AsyncWrite,
U: Encoder, U: Encoder,
{ {
let remaining = self.write_buf.remaining_mut(); let remaining = self.write_buf.capacity() - self.write_buf.len();
if remaining < LW { if remaining < LW {
self.write_buf.reserve(HW - remaining); self.write_buf.reserve(HW - remaining);
} }
@ -262,7 +262,7 @@ impl<T, U> Framed<T, U> {
debug_assert!(!self.flags.contains(Flags::EOF)); debug_assert!(!self.flags.contains(Flags::EOF));
// Otherwise, try to read more data and try again. Make sure we've got room // Otherwise, try to read more data and try again. Make sure we've got room
let remaining = self.read_buf.remaining_mut(); let remaining = self.read_buf.capacity() - self.read_buf.len();
if remaining < LW { if remaining < LW {
self.read_buf.reserve(HW - remaining) self.read_buf.reserve(HW - remaining)
} }