Skip to content

Commit f9f65b7

Browse files
authoredJul 10, 2023
feat(rt): replace IO traits with hyper::rt ones (#3230)
This replaces the usage of `tokio::io::{AsyncRead, AsyncWrite}` in hyper's public API with new traits in the `hyper::rt` module. Closes #3110 BREAKING CHANGE: Any IO transport type provided must not implement `hyper::rt::{Read, Write}` instead of `tokio::io` traits. You can grab a helper type from `hyper-util` to wrap Tokio types, or implement the traits yourself, if it's a custom type.
1 parent f4b5130 commit f9f65b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1015
-292
lines changed
 

‎benches/end_to_end.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
extern crate test;
55
mod support;
66

7-
// TODO: Reimplement Opts::bench using hyper::server::conn and hyper::client::conn
8-
// (instead of Server and HttpClient).
7+
// TODO: Reimplement parallel for HTTP/1
98

109
use std::convert::Infallible;
1110
use std::net::SocketAddr;
@@ -315,7 +314,8 @@ impl Opts {
315314

316315
let mut client = rt.block_on(async {
317316
if self.http2 {
318-
let io = tokio::net::TcpStream::connect(&addr).await.unwrap();
317+
let tcp = tokio::net::TcpStream::connect(&addr).await.unwrap();
318+
let io = support::TokioIo::new(tcp);
319319
let (tx, conn) = hyper::client::conn::http2::Builder::new(support::TokioExecutor)
320320
.initial_stream_window_size(self.http2_stream_window)
321321
.initial_connection_window_size(self.http2_conn_window)
@@ -328,7 +328,8 @@ impl Opts {
328328
} else if self.parallel_cnt > 1 {
329329
todo!("http/1 parallel >1");
330330
} else {
331-
let io = tokio::net::TcpStream::connect(&addr).await.unwrap();
331+
let tcp = tokio::net::TcpStream::connect(&addr).await.unwrap();
332+
let io = support::TokioIo::new(tcp);
332333
let (tx, conn) = hyper::client::conn::http1::Builder::new()
333334
.handshake(io)
334335
.await
@@ -414,14 +415,15 @@ fn spawn_server(rt: &tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
414415
let opts = opts.clone();
415416
rt.spawn(async move {
416417
while let Ok((sock, _)) = listener.accept().await {
418+
let io = support::TokioIo::new(sock);
417419
if opts.http2 {
418420
tokio::spawn(
419421
hyper::server::conn::http2::Builder::new(support::TokioExecutor)
420422
.initial_stream_window_size(opts.http2_stream_window)
421423
.initial_connection_window_size(opts.http2_conn_window)
422424
.adaptive_window(opts.http2_adaptive_window)
423425
.serve_connection(
424-
sock,
426+
io,
425427
service_fn(move |req: Request<hyper::body::Incoming>| async move {
426428
let mut req_body = req.into_body();
427429
while let Some(_chunk) = req_body.frame().await {}
@@ -433,7 +435,7 @@ fn spawn_server(rt: &tokio::runtime::Runtime, opts: &Opts) -> SocketAddr {
433435
);
434436
} else {
435437
tokio::spawn(hyper::server::conn::http1::Builder::new().serve_connection(
436-
sock,
438+
io,
437439
service_fn(move |req: Request<hyper::body::Incoming>| async move {
438440
let mut req_body = req.into_body();
439441
while let Some(_chunk) = req_body.frame().await {}

‎benches/pipeline.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
extern crate test;
55

6+
mod support;
7+
68
use std::convert::Infallible;
79
use std::io::{Read, Write};
810
use std::net::{SocketAddr, TcpStream};
@@ -40,11 +42,12 @@ fn hello_world_16(b: &mut test::Bencher) {
4042
rt.spawn(async move {
4143
loop {
4244
let (stream, _addr) = listener.accept().await.expect("accept");
45+
let io = support::TokioIo::new(stream);
4346

4447
http1::Builder::new()
4548
.pipeline_flush(true)
4649
.serve_connection(
47-
stream,
50+
io,
4851
service_fn(|_| async {
4952
Ok::<_, Infallible>(Response::new(Full::new(Bytes::from(
5053
"Hello, World!",

0 commit comments

Comments
 (0)
Please sign in to comment.