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:
@@ -1,9 +1,13 @@
|
||||
#![deny(warnings)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use futures_util::future::join;
|
||||
use hyper::service::{make_service_fn, service_fn};
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
use hyper::server::conn::Http;
|
||||
use hyper::service::service_fn;
|
||||
use hyper::{Body, Request, Response};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
static INDEX1: &[u8] = b"The 1st service!";
|
||||
static INDEX2: &[u8] = b"The 2nd service!";
|
||||
@@ -20,16 +24,40 @@ async fn index2(_: Request<Body>) -> Result<Response<Body>, hyper::Error> {
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
pretty_env_logger::init();
|
||||
|
||||
let addr1 = ([127, 0, 0, 1], 1337).into();
|
||||
let addr2 = ([127, 0, 0, 1], 1338).into();
|
||||
let addr1: SocketAddr = ([127, 0, 0, 1], 1337).into();
|
||||
let addr2: SocketAddr = ([127, 0, 0, 1], 1338).into();
|
||||
|
||||
let srv1 = Server::bind(&addr1).serve(make_service_fn(|_| async {
|
||||
Ok::<_, hyper::Error>(service_fn(index1))
|
||||
}));
|
||||
let srv1 = async move {
|
||||
let listener = TcpListener::bind(addr1).await.unwrap();
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await.unwrap();
|
||||
|
||||
let srv2 = Server::bind(&addr2).serve(make_service_fn(|_| async {
|
||||
Ok::<_, hyper::Error>(service_fn(index2))
|
||||
}));
|
||||
tokio::task::spawn(async move {
|
||||
if let Err(err) = Http::new()
|
||||
.serve_connection(stream, service_fn(index1))
|
||||
.await
|
||||
{
|
||||
println!("Error serving connection: {:?}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
let srv2 = async move {
|
||||
let listener = TcpListener::bind(addr2).await.unwrap();
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await.unwrap();
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
if let Err(err) = Http::new()
|
||||
.serve_connection(stream, service_fn(index2))
|
||||
.await
|
||||
{
|
||||
println!("Error serving connection: {:?}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
println!("Listening on http://{} and http://{}", addr1, addr2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user