From a226ed87525f73cba38c809a724c929bdd826ef8 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 30 Jul 2021 19:43:31 +0100 Subject: [PATCH] Keep some requests outstanding Signed-off-by: Ian Jackson --- src/bin/client.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bin/client.rs b/src/bin/client.rs index c13cb9c..2bbde41 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -94,7 +94,16 @@ async fn run_client( async { loop { select! { - packet = tx_stream.next_segment(), + packet = async { + // cancellation safety: if this future is polled, we might + // move out of tx_defer, but then we will be immediately + // ready and yield it inot packet + if let Some(y) = tx_defer.take() { + Ok(Some(y)) + } else { + tx_stream.next_segment().await + } + }, if tx_defer.is_none() && reqs.len() < ic.max_requests_outstanding.sat() => { @@ -130,6 +139,15 @@ async fn run_client( submit_request(&ic, &hclient, &mut reqs, upbound)?; } + () = async { }, + if reqs.len() < ic.target_requests_outstanding.sat() || + (tx_defer.is_some() && + reqs.len() < ic.max_requests_outstanding.sat()) => + { + let upbound = tx_defer.take().into_iter().collect_vec(); + submit_request(&ic, &hclient, &mut reqs, upbound)?; + } + (got, goti, _) = async { future::select_all(&mut reqs).await }, if ! reqs.is_empty() => { -- 2.30.2