chiark / gitweb /
Keep some requests outstanding
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 30 Jul 2021 18:43:31 +0000 (19:43 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 30 Jul 2021 18:43:31 +0000 (19:43 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs

index c13cb9c5875793fd4997802b06a79162e386a98d..2bbde41f427575f1c042a5c669ecf51d12a669a3 100644 (file)
@@ -94,7 +94,16 @@ async fn run_client<C:HCC>(
   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<C:HCC>(
           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() =>
         {