From: Ian Jackson Date: Wed, 28 Jul 2021 23:54:17 +0000 (+0100) Subject: client: wip code X-Git-Tag: hippotat/1.0.0~434 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=10d3f5683f829399730f8076ccf8cef8e1851938;p=hippotat.git client: wip code Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index bb147ac..c7b1f45 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -43,6 +43,8 @@ async fn run_client(ic: InstanceConfig, hclient: Arc>) let mut reqs = Vec::with_capacity(ic.max_requests_outstanding.sat()); + // xxx check that ic settings are all honoured + async { loop { select! { @@ -85,24 +87,37 @@ async fn run_client(ic: InstanceConfig, hclient: Arc>) Cow::from(&[SLIP_END] as &'static [u8]) ) ).context("construct request")?; - -// dbg!(&req); - -// hclient.request -/* - Body - made out of Stream - made out of futures::stream::iter - - - let datalen = - - let o = 0; - let i = -*/ - reqs.push(()); - // xxx make new request + let resp = hclient.request(req); + let fut = Box::pin(tokio::timeout( + ic.http_timeout, + async { + let r = async { + let resp = resp.await; + if ! resp.status().is_success() { + throw!("HTTP error status {}: {}", &resp.status()); + } + let resp = resp.into_body(); + // xxx: some size limit to avoid mallocing the universe + let resp = resp.aggregate().await + .context("HTTP error fetching response body")?; + Ok::<_,AE>(resp) + }; + if r.is_err() { + tokio::time::sleep(&ic.http_retry).await; + } + r + } + )); + reqs.push(fut); + } + + (got, goti, _) = future::select_all(&mut reqs) + { + reqs.swap_remove(goti); + if let Some(got) = reporter.report(got) { + dbg!(got.len()); // xxx + } } } }