1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-23 23:51:06 +01:00

remove buffer capacity for payload

This commit is contained in:
Nikolay Kim 2019-04-07 10:40:45 -07:00
parent 219baf3323
commit 3c650ca194
3 changed files with 5 additions and 13 deletions

View File

@ -59,6 +59,7 @@ base64 = "0.10"
bitflags = "1.0"
bytes = "0.4"
byteorder = "1.2"
copyless = "0.1.2"
derive_more = "0.14"
either = "1.5.2"
encoding = "0.2"

View File

@ -77,14 +77,6 @@ impl Payload {
pub fn unread_data(&mut self, data: Bytes) {
self.inner.borrow_mut().unread_data(data);
}
#[inline]
/// Set read buffer capacity
///
/// Default buffer capacity is 32Kb.
pub fn set_read_buffer_capacity(&mut self, cap: usize) {
self.inner.borrow_mut().capacity = cap;
}
}
impl Stream for Payload {
@ -153,7 +145,6 @@ struct Inner {
err: Option<PayloadError>,
need_read: bool,
items: VecDeque<Bytes>,
capacity: usize,
task: Option<Task>,
io_task: Option<Task>,
}
@ -166,7 +157,6 @@ impl Inner {
err: None,
items: VecDeque::new(),
need_read: true,
capacity: MAX_BUFFER_SIZE,
task: None,
io_task: None,
}
@ -186,7 +176,7 @@ impl Inner {
fn feed_data(&mut self, data: Bytes) {
self.len += data.len();
self.items.push_back(data);
self.need_read = self.len < self.capacity;
self.need_read = self.len < MAX_BUFFER_SIZE;
if let Some(task) = self.task.take() {
task.notify()
}
@ -200,7 +190,7 @@ impl Inner {
fn readany(&mut self) -> Poll<Option<Bytes>, PayloadError> {
if let Some(data) = self.items.pop_front() {
self.len -= data.len();
self.need_read = self.len < self.capacity;
self.need_read = self.len < MAX_BUFFER_SIZE;
if self.need_read && self.task.is_none() && !self.eof {
self.task = Some(current_task());

View File

@ -3,6 +3,7 @@ use std::collections::VecDeque;
use std::rc::Rc;
use bitflags::bitflags;
use copyless::BoxHelper;
use crate::extensions::Extensions;
use crate::header::HeaderMap;
@ -417,7 +418,7 @@ impl BoxedResponsePool {
BoxedResponseHead { head: Some(head) }
} else {
BoxedResponseHead {
head: Some(Box::new(ResponseHead::default())),
head: Some(Box::alloc().init(ResponseHead::default())),
}
}
}