feat(client,server): remove tcp feature and code (#2929)

This removes the `tcp` feature from hyper's `Cargo.toml`, and the code it enabled:

- `HttpConnector`
- `GaiResolver`
- `AddrStream`

And parts of `Client` and `Server` that used those types. Alternatives will be available in the `hyper-util` crate.

Closes #2856 
Co-authored-by: MrGunflame <mrgunflame@protonmail.com>
This commit is contained in:
Sean McArthur
2022-07-29 10:07:09 -07:00
committed by GitHub
parent d4b5bd4ee6
commit 0c8ee93d7f
40 changed files with 1565 additions and 2676 deletions

View File

@@ -3,84 +3,87 @@
extern crate test;
use std::io::{Read, Write};
use std::net::TcpStream;
use std::sync::mpsc;
use std::time::Duration;
// TODO: Reimplement hello_world_16 bench using hyper::server::conn
// (instead of Server).
use tokio::sync::oneshot;
// use std::io::{Read, Write};
// use std::net::TcpStream;
// use std::sync::mpsc;
// use std::time::Duration;
use hyper::service::{make_service_fn, service_fn};
use hyper::{Body, Response, Server};
// use tokio::sync::oneshot;
const PIPELINED_REQUESTS: usize = 16;
// use hyper::service::{make_service_fn, service_fn};
// use hyper::{Body, Response, Server};
#[bench]
fn hello_world_16(b: &mut test::Bencher) {
let _ = pretty_env_logger::try_init();
let (_until_tx, until_rx) = oneshot::channel::<()>();
// const PIPELINED_REQUESTS: usize = 16;
let addr = {
let (addr_tx, addr_rx) = mpsc::channel();
std::thread::spawn(move || {
let addr = "127.0.0.1:0".parse().unwrap();
// #[bench]
// fn hello_world_16(b: &mut test::Bencher) {
// let _ = pretty_env_logger::try_init();
// let (_until_tx, until_rx) = oneshot::channel::<()>();
let make_svc = make_service_fn(|_| async {
Ok::<_, hyper::Error>(service_fn(|_| async {
Ok::<_, hyper::Error>(Response::new(Body::from("Hello, World!")))
}))
});
// let addr = {
// let (addr_tx, addr_rx) = mpsc::channel();
// std::thread::spawn(move || {
// let addr = "127.0.0.1:0".parse().unwrap();
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("rt build");
let srv = rt.block_on(async move {
Server::bind(&addr)
.http1_pipeline_flush(true)
.serve(make_svc)
});
// let make_svc = make_service_fn(|_| async {
// Ok::<_, hyper::Error>(service_fn(|_| async {
// Ok::<_, hyper::Error>(Response::new(Body::from("Hello, World!")))
// }))
// });
addr_tx.send(srv.local_addr()).unwrap();
// let rt = tokio::runtime::Builder::new_current_thread()
// .enable_all()
// .build()
// .expect("rt build");
// let srv = rt.block_on(async move {
// Server::bind(&addr)
// .http1_pipeline_flush(true)
// .serve(make_svc)
// });
let graceful = srv.with_graceful_shutdown(async {
until_rx.await.ok();
});
// addr_tx.send(srv.local_addr()).unwrap();
rt.block_on(async {
if let Err(e) = graceful.await {
panic!("server error: {}", e);
}
});
});
// let graceful = srv.with_graceful_shutdown(async {
// until_rx.await.ok();
// });
addr_rx.recv().unwrap()
};
// rt.block_on(async {
// if let Err(e) = graceful.await {
// panic!("server error: {}", e);
// }
// });
// });
let mut pipelined_reqs = Vec::new();
for _ in 0..PIPELINED_REQUESTS {
pipelined_reqs.extend_from_slice(b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
}
// addr_rx.recv().unwrap()
// };
let total_bytes = {
let mut tcp = TcpStream::connect(addr).unwrap();
tcp.write_all(b"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")
.unwrap();
let mut buf = Vec::new();
tcp.read_to_end(&mut buf).unwrap()
} * PIPELINED_REQUESTS;
// let mut pipelined_reqs = Vec::new();
// for _ in 0..PIPELINED_REQUESTS {
// pipelined_reqs.extend_from_slice(b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n");
// }
let mut tcp = TcpStream::connect(addr).unwrap();
tcp.set_read_timeout(Some(Duration::from_secs(3))).unwrap();
let mut buf = [0u8; 8192];
// let total_bytes = {
// let mut tcp = TcpStream::connect(addr).unwrap();
// tcp.write_all(b"GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")
// .unwrap();
// let mut buf = Vec::new();
// tcp.read_to_end(&mut buf).unwrap()
// } * PIPELINED_REQUESTS;
b.bytes = (pipelined_reqs.len() + total_bytes) as u64;
b.iter(|| {
tcp.write_all(&pipelined_reqs).unwrap();
let mut sum = 0;
while sum < total_bytes {
sum += tcp.read(&mut buf).unwrap();
}
assert_eq!(sum, total_bytes);
});
}
// let mut tcp = TcpStream::connect(addr).unwrap();
// tcp.set_read_timeout(Some(Duration::from_secs(3))).unwrap();
// let mut buf = [0u8; 8192];
// b.bytes = (pipelined_reqs.len() + total_bytes) as u64;
// b.iter(|| {
// tcp.write_all(&pipelined_reqs).unwrap();
// let mut sum = 0;
// while sum < total_bytes {
// sum += tcp.read(&mut buf).unwrap();
// }
// assert_eq!(sum, total_bytes);
// });
// }