Add Codec::set_max_send_frame_size

This commit is contained in:
Carl Lerche
2017-09-05 14:01:32 -07:00
parent c2e6eb35d8
commit 0cc611df35
7 changed files with 81 additions and 25 deletions

View File

@@ -49,10 +49,6 @@ impl<T> FramedRead<T> {
}
}
pub fn apply_remote_settings(&mut self, _settings: &frame::Settings) {
// TODO: Is this needed?
}
fn decode_frame(&mut self, mut bytes: BytesMut) -> Result<Option<Frame>, RecvError> {
use self::RecvError::*;

View File

@@ -224,11 +224,10 @@ impl<T, B> FramedWrite<T, B> {
self.max_frame_size as usize
}
/// Apply settings received by the peer
pub fn apply_remote_settings(&mut self, settings: &frame::Settings) {
if let Some(val) = settings.max_frame_size() {
self.max_frame_size = val;
}
/// Set the peer's max frame size.
pub fn set_max_frame_size(&mut self, val: usize) {
assert!(val <= frame::MAX_MAX_FRAME_SIZE);
self.max_frame_size = val as FrameSize;
}
/// Retrieve the last data frame that has been sent

View File

@@ -7,7 +7,7 @@ pub use self::error::{SendError, RecvError, UserError};
use self::framed_read::FramedRead;
use self::framed_write::FramedWrite;
use frame::{self, Frame, Data, Settings};
use frame::{self, Frame, Data};
use futures::*;
@@ -49,33 +49,30 @@ impl<T, B> Codec<T, B>
}
impl<T, B> Codec<T, B> {
/// Apply a settings received from the peer
pub fn apply_remote_settings(&mut self, frame: &Settings) {
self.framed_read().apply_remote_settings(frame);
self.framed_write().apply_remote_settings(frame);
}
/// Takes the data payload value that was fully written to the socket
pub fn take_last_data_frame(&mut self) -> Option<Data<B>> {
self.framed_write().take_last_data_frame()
}
/// Returns the max frame size that can be sent to the peer
/// Returns the max frame size that can be sent to the peer.
pub fn max_send_frame_size(&self) -> usize {
self.inner.get_ref().max_frame_size()
}
/// Set the peer's max frame size.
pub fn set_max_send_frame_size(&mut self, val: usize) {
self.framed_write().set_max_frame_size(val)
}
/// Get a reference to the inner stream.
#[cfg(feature = "unstable")]
pub fn get_ref(&self) -> &T {
self.inner.get_ref().get_ref()
}
/// Get a mutable reference to the inner stream.
pub fn get_mut(&mut self) -> &mut T {
self.inner.get_mut().get_mut()
}
fn framed_read(&mut self) -> &mut FramedRead<FramedWrite<T, B>> {
&mut self.inner
/// Takes the data payload value that was fully written to the socket
pub(crate) fn take_last_data_frame(&mut self) -> Option<Data<B>> {
self.framed_write().take_last_data_frame()
}
fn framed_write(&mut self) -> &mut FramedWrite<T, B> {

View File

@@ -55,6 +55,8 @@ pub use self::window_update::WindowUpdate;
pub use self::settings::{
DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
DEFAULT_MAX_FRAME_SIZE,
MAX_INITIAL_WINDOW_SIZE,
MAX_MAX_FRAME_SIZE,
};
pub type FrameSize = u32;

View File

@@ -33,10 +33,16 @@ pub struct SettingsFlags(u8);
const ACK: u8 = 0x1;
const ALL: u8 = ACK;
/// The default value of SETTINGS_HEADER_TABLE_SIZE
pub const DEFAULT_SETTINGS_HEADER_TABLE_SIZE: usize = 4_096;
/// The default value of MAX_FRAME_SIZE
pub const DEFAULT_MAX_FRAME_SIZE: FrameSize = 16_384;
/// INITIAL_WINDOW_SIZE upper bound
pub const MAX_INITIAL_WINDOW_SIZE: usize = (1 << 31) - 1;
/// MAX_FRAME_SIZE upper bound
pub const MAX_MAX_FRAME_SIZE: usize = (1 << 24) - 1;
// ===== impl Settings =====

View File

@@ -52,7 +52,10 @@ impl Settings {
trace!("ACK sent; applying settings");
dst.apply_remote_settings(settings);
if let Some(val) = settings.max_frame_size() {
dst.set_max_send_frame_size(val as usize);
}
streams.apply_remote_settings(settings)?;
}

View File

@@ -11,6 +11,12 @@ fn read_none() {
assert_closed!(codec);
}
#[test]
fn read_frame_too_big() {
}
// ===== DATA =====
#[test]
fn read_data_no_padding() {
let mut codec = raw_codec! {
@@ -28,6 +34,39 @@ fn read_data_no_padding() {
assert_closed!(codec);
}
#[test]
fn read_data_empty_payload() {
let mut codec = raw_codec! {
read => [
0, 0, 0, 0, 0, 0, 0, 0, 1,
];
};
let data = poll_data!(codec);
assert_eq!(data.stream_id(), 1);
assert_eq!(data.payload(), &b""[..]);
assert!(!data.is_end_stream());
assert_closed!(codec);
}
#[test]
fn read_data_end_stream() {
let mut codec = raw_codec! {
read => [
0, 0, 5, 0, 1, 0, 0, 0, 1,
"hello",
];
};
let data = poll_data!(codec);
assert_eq!(data.stream_id(), 1);
assert_eq!(data.payload(), &b"hello"[..]);
assert!(data.is_end_stream());
assert_closed!(codec);
}
#[test]
fn read_data_padding() {
let mut codec = raw_codec! {
@@ -58,3 +97,17 @@ fn read_data_stream_id_zero() {
poll_err!(codec);
}
// ===== HEADERS =====
#[test]
fn read_headers_without_pseudo() {
}
#[test]
fn read_headers_with_pseudo() {
}
#[test]
fn read_headers_empty_payload() {
}