New send flow control (#25)

Restructure send flow control such that sending data is always accepted by `Stream`. Data frames will be buffered until there is available window to send them. Producers can monitor the available window capacity to decide if data should be produced.
This commit is contained in:
Carl Lerche
2017-08-21 13:52:58 -07:00
committed by GitHub
parent 41b25a4a56
commit a623ab68b5
13 changed files with 715 additions and 736 deletions

View File

@@ -1,3 +1,53 @@
pub mod support;
use support::*;
// In this case, the stream & connection both have capacity, but capacity is not
// explicitly requested.
#[test]
fn send_data_without_requesting_capacity() {
let _ = ::env_logger::init();
let payload = [0; 1024];
let mock = mock_io::Builder::new()
.handshake()
.write(&[
// POST /
0, 0, 16, 1, 4, 0, 0, 0, 1, 131, 135, 65, 139, 157, 41,
172, 75, 143, 168, 233, 25, 151, 33, 233, 132,
])
.write(&[
// DATA
0, 4, 0, 0, 1, 0, 0, 0, 1,
])
.write(&payload[..])
.write(frames::SETTINGS_ACK)
// Read response
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock)
.wait().unwrap();
let request = Request::builder()
.method(method::POST)
.uri("https://http2.akamai.com/")
.body(()).unwrap();
let mut stream = h2.request(request, false).unwrap();
// The capacity should be immediately allocated
assert_eq!(stream.capacity(), 0);
// Send the data
stream.send_data(payload[..].into(), true).unwrap();
// Get the response
let resp = h2.run(poll_fn(|| stream.poll_response())).unwrap();
assert_eq!(resp.status(), status::NO_CONTENT);
h2.wait().unwrap();
}
#[test]
#[ignore]

View File

@@ -34,6 +34,12 @@ fn single_stream_send_large_body() {
let mut stream = h2.request(request, false).unwrap();
// Reserve capacity to send the payload
stream.reserve_capacity(payload.len()).unwrap();
// The capacity should be immediately allocated
assert_eq!(stream.capacity(), payload.len());
// Send the data
stream.send_data(payload[..].into(), true).unwrap();
@@ -82,6 +88,11 @@ fn single_stream_send_extra_large_body_multi_frames_one_buffer() {
let mut stream = h2.request(request, false).unwrap();
stream.reserve_capacity(payload.len()).unwrap();
// The capacity should be immediately allocated
assert_eq!(stream.capacity(), payload.len());
// Send the data
stream.send_data(payload.into(), true).unwrap();
@@ -142,6 +153,11 @@ fn single_stream_send_extra_large_body_multi_frames_multi_buffer() {
let mut stream = h2.request(request, false).unwrap();
stream.reserve_capacity(payload.len()).unwrap();
// The capacity should be immediately allocated
assert_eq!(stream.capacity(), payload.len());
// Send the data
stream.send_data(payload.into(), true).unwrap();

View File

@@ -74,6 +74,11 @@ fn send_recv_data() {
info!("sending request");
let mut stream = h2.request(request, false).unwrap();
// Reserve send capacity
stream.reserve_capacity(5).unwrap();
assert_eq!(stream.capacity(), 5);
// Send the data
stream.send_data("hello", true).unwrap();