Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No futures #594

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ byte-unit = "5.1.4"
clap = { version = "4.5.9", features = ["derive"] }
float-ord = "0.3.2"
flume = "0.11"
futures = "0.3.30"
humantime = "2.1.0"
libc = "0.2.155"
serde = { version = "1.0.204", features = ["derive"] }
Expand Down
34 changes: 7 additions & 27 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use http_body_util::Full;
use hyper::{
body::{Body, Incoming},
http,
};
use http_body_util::{BodyExt, Full};
use hyper::http;
use hyper_util::rt::{TokioExecutor, TokioIo};
use rand::prelude::*;
use std::{
pin::Pin,
sync::{
atomic::{AtomicBool, Ordering::Relaxed},
Arc,
Expand Down Expand Up @@ -485,10 +481,7 @@ impl Client {
connection_time = Some(ConnectionTime { dns_lookup, dialup });
send_request
};
while futures::future::poll_fn(|ctx| send_request.poll_ready(ctx))
.await
.is_err()
{
while send_request.ready().await.is_err() {
// This gets hit when the connection for HTTP/1.1 faults
// This re-connects
start = std::time::Instant::now();
Expand All @@ -505,11 +498,7 @@ impl Client {
let mut status = parts.status;

let mut len_sum = 0;
while let Some(chunk) = futures::future::poll_fn(|cx| {
Incoming::poll_frame(Pin::new(&mut stream), cx)
})
.await
{
while let Some(chunk) = stream.frame().await {
len_sum += chunk?.data_ref().map(|d| d.len()).unwrap_or_default();
}

Expand Down Expand Up @@ -595,11 +584,7 @@ impl Client {
let status = parts.status;

let mut len_sum = 0;
while let Some(chunk) = futures::future::poll_fn(|cx| {
Incoming::poll_frame(Pin::new(&mut stream), cx)
})
.await
{
while let Some(chunk) = stream.frame().await {
len_sum += chunk?.data_ref().map(|d| d.len()).unwrap_or_default();
}

Expand Down Expand Up @@ -663,10 +648,7 @@ impl Client {
(stream, Some(send_request))
};

while futures::future::poll_fn(|ctx| send_request.poll_ready(ctx))
.await
.is_err()
{
while send_request.ready().await.is_err() {
let (_dns_lookup, stream) = self.client_http1(&url, rng).await?;
send_request = stream;
}
Expand All @@ -683,9 +665,7 @@ impl Client {
let mut status = parts.status;

let mut len_sum = 0;
while let Some(chunk) =
futures::future::poll_fn(|cx| Incoming::poll_frame(Pin::new(&mut stream), cx)).await
{
while let Some(chunk) = stream.frame().await {
len_sum += chunk?.data_ref().map(|d| d.len()).unwrap_or_default();
}

Expand Down
33 changes: 14 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::Context;
use clap::Parser;
use crossterm::tty::IsTty;
use futures::prelude::*;
use hickory_resolver::config::{ResolverConfig, ResolverOpts};
use humantime::Duration;
use hyper::http::{
Expand Down Expand Up @@ -450,7 +449,6 @@ async fn main() -> anyhow::Result<()> {
resolver_opts.ip_strategy = ip_strategy;
let resolver = hickory_resolver::AsyncResolver::tokio(config, resolver_opts);

// client_builder builds client for each workers
let client = client::Client {
http_version,
url_generator,
Expand Down Expand Up @@ -490,25 +488,22 @@ async fn main() -> anyhow::Result<()> {

let data_collector = if opts.no_tui || !std::io::stdout().is_tty() {
// When `--no-tui` is enabled, just collect all data.
tokio::spawn(
async move {
let mut all: ResultData = Default::default();
tokio::select! {
_ = async {
while let Ok(report) = result_rx.recv_async().await {
all.push(report);
}
} => {}
_ = tokio::signal::ctrl_c() => {
// User pressed ctrl-c.
let _ = printer::print_result(&mut std::io::stdout(), print_mode, start, &all, start.elapsed(), opts.disable_color, opts.stats_success_breakdown);
std::process::exit(libc::EXIT_SUCCESS);
}
tokio::spawn(async move {
let mut all: ResultData = Default::default();
tokio::select! {
_ = async {
while let Ok(report) = result_rx.recv_async().await {
all.push(report);
}
} => {}
_ = tokio::signal::ctrl_c() => {
// User pressed ctrl-c.
let _ = printer::print_result(&mut std::io::stdout(), print_mode, start, &all, start.elapsed(), opts.disable_color, opts.stats_success_breakdown);
std::process::exit(libc::EXIT_SUCCESS);
}
all
}
.map(Ok),
)
Ok(all)
})
} else {
// Spawn monitor future which draws realtime tui
tokio::spawn(
Expand Down