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,7 +1,10 @@
|
||||
use hyper::server::conn::Http;
|
||||
use hyper::service::Service;
|
||||
use hyper::{Body, Request, Response, Server};
|
||||
use hyper::{Body, Request, Response};
|
||||
use tokio::net::TcpListener;
|
||||
|
||||
use std::future::Future;
|
||||
use std::net::SocketAddr;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
@@ -9,13 +12,23 @@ type Counter = i32;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let addr = ([127, 0, 0, 1], 3000).into();
|
||||
let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
|
||||
|
||||
let server = Server::bind(&addr).serve(MakeSvc { counter: 81818 });
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
println!("Listening on http://{}", addr);
|
||||
|
||||
server.await?;
|
||||
Ok(())
|
||||
loop {
|
||||
let (stream, _) = listener.accept().await?;
|
||||
|
||||
tokio::task::spawn(async move {
|
||||
if let Err(err) = Http::new()
|
||||
.serve_connection(stream, Svc { counter: 81818 })
|
||||
.await
|
||||
{
|
||||
println!("Failed to serve connection: {:?}", err);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
struct Svc {
|
||||
@@ -54,23 +67,3 @@ impl Service<Request<Body>> for Svc {
|
||||
Box::pin(async { res })
|
||||
}
|
||||
}
|
||||
|
||||
struct MakeSvc {
|
||||
counter: Counter,
|
||||
}
|
||||
|
||||
impl<T> Service<T> for MakeSvc {
|
||||
type Response = Svc;
|
||||
type Error = hyper::Error;
|
||||
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
|
||||
|
||||
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn call(&mut self, _: T) -> Self::Future {
|
||||
let counter = self.counter.clone();
|
||||
let fut = async move { Ok(Svc { counter }) };
|
||||
Box::pin(fut)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user