Add Codec::set_max_send_frame_size
This commit is contained in:
@@ -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> {
|
fn decode_frame(&mut self, mut bytes: BytesMut) -> Result<Option<Frame>, RecvError> {
|
||||||
use self::RecvError::*;
|
use self::RecvError::*;
|
||||||
|
|
||||||
|
|||||||
@@ -224,11 +224,10 @@ impl<T, B> FramedWrite<T, B> {
|
|||||||
self.max_frame_size as usize
|
self.max_frame_size as usize
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Apply settings received by the peer
|
/// Set the peer's max frame size.
|
||||||
pub fn apply_remote_settings(&mut self, settings: &frame::Settings) {
|
pub fn set_max_frame_size(&mut self, val: usize) {
|
||||||
if let Some(val) = settings.max_frame_size() {
|
assert!(val <= frame::MAX_MAX_FRAME_SIZE);
|
||||||
self.max_frame_size = val;
|
self.max_frame_size = val as FrameSize;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve the last data frame that has been sent
|
/// Retrieve the last data frame that has been sent
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ pub use self::error::{SendError, RecvError, UserError};
|
|||||||
use self::framed_read::FramedRead;
|
use self::framed_read::FramedRead;
|
||||||
use self::framed_write::FramedWrite;
|
use self::framed_write::FramedWrite;
|
||||||
|
|
||||||
use frame::{self, Frame, Data, Settings};
|
use frame::{self, Frame, Data};
|
||||||
|
|
||||||
use futures::*;
|
use futures::*;
|
||||||
|
|
||||||
@@ -49,33 +49,30 @@ impl<T, B> Codec<T, B>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B> Codec<T, B> {
|
impl<T, B> Codec<T, B> {
|
||||||
/// Apply a settings received from the peer
|
/// Returns the max frame size that can be sent to 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
|
|
||||||
pub fn max_send_frame_size(&self) -> usize {
|
pub fn max_send_frame_size(&self) -> usize {
|
||||||
self.inner.get_ref().max_frame_size()
|
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")]
|
#[cfg(feature = "unstable")]
|
||||||
pub fn get_ref(&self) -> &T {
|
pub fn get_ref(&self) -> &T {
|
||||||
self.inner.get_ref().get_ref()
|
self.inner.get_ref().get_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get a mutable reference to the inner stream.
|
||||||
pub fn get_mut(&mut self) -> &mut T {
|
pub fn get_mut(&mut self) -> &mut T {
|
||||||
self.inner.get_mut().get_mut()
|
self.inner.get_mut().get_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn framed_read(&mut self) -> &mut FramedRead<FramedWrite<T, B>> {
|
/// Takes the data payload value that was fully written to the socket
|
||||||
&mut self.inner
|
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> {
|
fn framed_write(&mut self) -> &mut FramedWrite<T, B> {
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ pub use self::window_update::WindowUpdate;
|
|||||||
pub use self::settings::{
|
pub use self::settings::{
|
||||||
DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
|
DEFAULT_SETTINGS_HEADER_TABLE_SIZE,
|
||||||
DEFAULT_MAX_FRAME_SIZE,
|
DEFAULT_MAX_FRAME_SIZE,
|
||||||
|
MAX_INITIAL_WINDOW_SIZE,
|
||||||
|
MAX_MAX_FRAME_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type FrameSize = u32;
|
pub type FrameSize = u32;
|
||||||
|
|||||||
@@ -33,10 +33,16 @@ pub struct SettingsFlags(u8);
|
|||||||
const ACK: u8 = 0x1;
|
const ACK: u8 = 0x1;
|
||||||
const ALL: u8 = ACK;
|
const ALL: u8 = ACK;
|
||||||
|
|
||||||
|
/// The default value of SETTINGS_HEADER_TABLE_SIZE
|
||||||
pub const DEFAULT_SETTINGS_HEADER_TABLE_SIZE: usize = 4_096;
|
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;
|
pub const DEFAULT_MAX_FRAME_SIZE: FrameSize = 16_384;
|
||||||
|
|
||||||
|
/// INITIAL_WINDOW_SIZE upper bound
|
||||||
pub const MAX_INITIAL_WINDOW_SIZE: usize = (1 << 31) - 1;
|
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;
|
pub const MAX_MAX_FRAME_SIZE: usize = (1 << 24) - 1;
|
||||||
|
|
||||||
// ===== impl Settings =====
|
// ===== impl Settings =====
|
||||||
|
|||||||
@@ -52,7 +52,10 @@ impl Settings {
|
|||||||
|
|
||||||
trace!("ACK sent; applying 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)?;
|
streams.apply_remote_settings(settings)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ fn read_none() {
|
|||||||
assert_closed!(codec);
|
assert_closed!(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_frame_too_big() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== DATA =====
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_data_no_padding() {
|
fn read_data_no_padding() {
|
||||||
let mut codec = raw_codec! {
|
let mut codec = raw_codec! {
|
||||||
@@ -28,6 +34,39 @@ fn read_data_no_padding() {
|
|||||||
assert_closed!(codec);
|
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]
|
#[test]
|
||||||
fn read_data_padding() {
|
fn read_data_padding() {
|
||||||
let mut codec = raw_codec! {
|
let mut codec = raw_codec! {
|
||||||
@@ -58,3 +97,17 @@ fn read_data_stream_id_zero() {
|
|||||||
|
|
||||||
poll_err!(codec);
|
poll_err!(codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== HEADERS =====
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_headers_without_pseudo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_headers_with_pseudo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_headers_empty_payload() {
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user