From: Ian Jackson Date: Fri, 30 Jul 2021 18:43:31 +0000 (+0100) Subject: Keep some requests outstanding X-Git-Tag: hippotat/1.0.0~421 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=a226ed87525f73cba38c809a724c929bdd826ef8;p=hippotat.git Keep some requests outstanding Signed-off-by: Ian Jackson --- 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() => {