closer to flow control

This commit is contained in:
Oliver Gould
2017-07-12 21:04:58 +00:00
parent b9f3556070
commit 41ffd1d44f
11 changed files with 337 additions and 179 deletions

View File

@@ -4,6 +4,7 @@ use bytes::{BufMut, Bytes, Buf};
#[derive(Debug)]
pub struct Data<T = Bytes> {
stream_id: StreamId,
data_len: usize,
data: T,
flags: DataFlag,
pad_len: Option<u8>,
@@ -26,9 +27,9 @@ impl Data<Bytes> {
} else {
None
};
Ok(Data {
stream_id: head.stream_id(),
data_len: payload.len(),
data: payload,
flags: flags,
pad_len: pad_len,
@@ -37,15 +38,6 @@ impl Data<Bytes> {
}
impl<T> Data<T> {
pub fn new(stream_id: StreamId, data: T) -> Self {
Data {
stream_id: stream_id,
data: data,
flags: DataFlag::default(),
pad_len: None,
}
}
pub fn stream_id(&self) -> StreamId {
self.stream_id
}
@@ -62,14 +54,24 @@ impl<T> Data<T> {
Head::new(Kind::Data, self.flags.into(), self.stream_id)
}
pub fn len(&self) -> usize {
self.data_len
}
pub fn into_payload(self) -> T {
self.data
}
}
impl<T: Buf> Data<T> {
pub fn len(&self) -> usize {
self.data.remaining()
pub fn from_buf(stream_id: StreamId, data: T) -> Self {
Data {
stream_id: stream_id,
data_len: data.remaining(),
data: data,
flags: DataFlag::default(),
pad_len: None,
}
}
pub fn encode_chunk<U: BufMut>(&mut self, dst: &mut U) {

View File

@@ -113,11 +113,6 @@ pub enum Error {
Hpack(hpack::DecoderError),
}
// ===== impl Frame ======
impl Frame {
}
// ===== impl Error =====
impl From<Error> for ConnectionError {

View File

@@ -18,6 +18,12 @@ pub struct SettingSet {
max_header_list_size: Option<u32>,
}
impl SettingSet {
pub fn initial_window_size(&self) -> u32 {
self.initial_window_size.unwrap_or(65_535)
}
}
/// An enum that lists all valid settings that can be sent in a SETTINGS
/// frame.
///

View File

@@ -5,7 +5,7 @@ use frame::{self, Head, Kind, Error};
const SIZE_INCREMENT_MASK: u32 = 1 << 31;
#[derive(Debug)]
#[derive(Copy, Clone, Debug)]
pub struct WindowUpdate {
stream_id: StreamId,
size_increment: u32,
@@ -52,8 +52,8 @@ impl WindowUpdate {
}
}
impl From<WindowUpdate> for frame::Frame {
fn from(src: WindowUpdate) -> frame::Frame {
impl<B> From<WindowUpdate> for frame::Frame<B> {
fn from(src: WindowUpdate) -> Self {
frame::Frame::WindowUpdate(src)
}
}