split Client into (Client, Connection) (#107)

The Connection type is a `Future` that drives all of the IO of the
client connection.

The Client type is separate, and is used to send requests into the
connection.
This commit is contained in:
Sean McArthur
2017-09-28 16:55:12 -07:00
committed by GitHub
parent 510800ef28
commit f8efb053b9
23 changed files with 489 additions and 262 deletions

View File

@@ -27,7 +27,7 @@ fn send_data_without_requesting_capacity() {
.read(&[0, 0, 1, 1, 5, 0, 0, 0, 1, 0x89])
.build();
let mut h2 = Client::handshake(mock).wait().unwrap();
let (mut client, mut h2) = Client::handshake(mock).wait().unwrap();
let request = Request::builder()
.method(Method::POST)
@@ -35,7 +35,7 @@ fn send_data_without_requesting_capacity() {
.body(())
.unwrap();
let mut stream = h2.send_request(request, false).unwrap();
let mut stream = client.send_request(request, false).unwrap();
// The capacity should be immediately allocated
assert_eq!(stream.capacity(), 0);
@@ -82,14 +82,14 @@ fn release_capacity_sends_window_update() {
// gotta end the connection
.map(drop);
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let h2 = Client::handshake(io).unwrap().and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.send_request(request, true).unwrap()
let req = client.send_request(request, true).unwrap()
.unwrap()
// Get the response
.and_then(|resp| {
@@ -145,14 +145,14 @@ fn release_capacity_of_small_amount_does_not_send_window_update() {
// gotta end the connection
.map(drop);
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let h2 = Client::handshake(io).unwrap().and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.send_request(request, true).unwrap()
let req = client.send_request(request, true).unwrap()
.unwrap()
// Get the response
.and_then(|resp| {
@@ -212,14 +212,15 @@ fn recv_data_overflows_connection_window() {
.recv_frame(frames::go_away(0).flow_control());
// connection is ended by client
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let h2 = Client::handshake(io).unwrap().and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.send_request(request, true)
let req = client
.send_request(request, true)
.unwrap()
.unwrap()
.and_then(|resp| {
@@ -281,14 +282,15 @@ fn recv_data_overflows_stream_window() {
.initial_window_size(16_384)
.handshake::<_, Bytes>(io)
.unwrap()
.and_then(|mut h2| {
.and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::GET)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let req = h2.send_request(request, true)
let req = client
.send_request(request, true)
.unwrap()
.unwrap()
.and_then(|resp| {
@@ -333,7 +335,7 @@ fn stream_close_by_data_frame_releases_capacity() {
let window_size = frame::DEFAULT_INITIAL_WINDOW_SIZE as usize;
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let h2 = Client::handshake(io).unwrap().and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
@@ -341,7 +343,7 @@ fn stream_close_by_data_frame_releases_capacity() {
.unwrap();
// Send request
let mut s1 = h2.send_request(request, false).unwrap();
let mut s1 = client.send_request(request, false).unwrap();
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
@@ -357,7 +359,7 @@ fn stream_close_by_data_frame_releases_capacity() {
.unwrap();
// Create a second stream
let mut s2 = h2.send_request(request, false).unwrap();
let mut s2 = client.send_request(request, false).unwrap();
// Request capacity
s2.reserve_capacity(5);
@@ -401,7 +403,7 @@ fn stream_close_by_trailers_frame_releases_capacity() {
let window_size = frame::DEFAULT_INITIAL_WINDOW_SIZE as usize;
let h2 = Client::handshake(io).unwrap().and_then(|mut h2| {
let h2 = Client::handshake(io).unwrap().and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
@@ -409,7 +411,7 @@ fn stream_close_by_trailers_frame_releases_capacity() {
.unwrap();
// Send request
let mut s1 = h2.send_request(request, false).unwrap();
let mut s1 = client.send_request(request, false).unwrap();
// This effectively reserves the entire connection window
s1.reserve_capacity(window_size);
@@ -425,7 +427,7 @@ fn stream_close_by_trailers_frame_releases_capacity() {
.unwrap();
// Create a second stream
let mut s2 = h2.send_request(request, false).unwrap();
let mut s2 = client.send_request(request, false).unwrap();
// Request capacity
s2.reserve_capacity(5);
@@ -504,14 +506,14 @@ fn recv_window_update_on_stream_closed_by_data_frame() {
let h2 = Client::handshake(io)
.unwrap()
.and_then(|mut h2| {
.and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let stream = h2.send_request(request, false).unwrap();
let stream = client.send_request(request, false).unwrap();
// Wait for the response
h2.drive(GetResponse {
@@ -547,14 +549,14 @@ fn reserved_capacity_assigned_in_multi_window_updates() {
let h2 = Client::handshake(io)
.unwrap()
.and_then(|mut h2| {
.and_then(|(mut client, h2)| {
let request = Request::builder()
.method(Method::POST)
.uri("https://http2.akamai.com/")
.body(())
.unwrap();
let mut stream = h2.send_request(request, false).unwrap();
let mut stream = client.send_request(request, false).unwrap();
// Consume the capacity
let payload = vec![0; frame::DEFAULT_INITIAL_WINDOW_SIZE as usize];
@@ -674,17 +676,19 @@ fn connection_notified_on_released_capacity() {
let th2 = thread::spawn(move || {
let h2 = Client::handshake(io).wait().unwrap();
let (mut client, h2) = Client::handshake(io).wait().unwrap();
let (mut h2, _) = h2.drive(settings_rx).wait().unwrap();
let (h2, _) = h2.drive(settings_rx).wait().unwrap();
let request = Request::get("https://example.com/a").body(()).unwrap();
tx.send(h2.send_request(request, true).unwrap()).unwrap();
tx.send(client.send_request(request, true).unwrap())
.unwrap();
let request = Request::get("https://example.com/b").body(()).unwrap();
tx.send(h2.send_request(request, true).unwrap()).unwrap();
tx.send(client.send_request(request, true).unwrap())
.unwrap();
// Run the connection to completion
h2.wait().unwrap();