From: Ian Jackson Date: Sun, 25 Jul 2021 23:50:53 +0000 (+0100) Subject: client: wip X-Git-Tag: hippotat/1.0.0~439 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=db96c142018382d7d9871bce8c5c560dc64bb180;p=hippotat.git client: wip Signed-off-by: Ian Jackson --- diff --git a/src/bin/client.rs b/src/bin/client.rs index f01bb6f..3abfc19 100644 --- a/src/bin/client.rs +++ b/src/bin/client.rs @@ -35,16 +35,26 @@ async fn run_client(ic: InstanceConfig, hclient: Arc>) Ok::<_,io::Error>(()) }); - let stream_for_tx = ipif.stdout.take().unwrap(); + let max_outstanding = ic.max_requests_outstanding + .try_into().unwrap_or(usize::MAX); + + let tx_stream = ipif.stdout.take().unwrap(); + let mut tx_stream = tokio::io::BufReader::new(tx_stream).split(SLIP_ESC); let stream_for_rx = ipif.stdin .take().unwrap(); -// let txbuf = VecDeque::new(); -/* + let mut reqs = Vec::with_capacity(max_outstanding); + async { loop { select! { - rx = stream_for_rx - */ - throw!(anyhow!("arrgh")); + packet = tx_stream.next_segment(), + if reqs.len() < max_outstanding => { + let packet = packet.context("read from ipif")?; + reqs.push(()); + // xxx make new request + } + } + } + }.await } #[tokio::main] diff --git a/src/prelude.rs b/src/prelude.rs index b1d7938..4198ed9 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -3,6 +3,7 @@ // There is NO WARRANTY. pub use std::collections::{BTreeSet, HashMap}; +pub use std::convert::TryInto; pub use std::cmp::{min, max}; pub use std::fs; pub use std::fmt::{self, Debug, Display}; @@ -28,6 +29,7 @@ pub use lazy_regex::{regex_is_match, regex_replace_all}; pub use log::{debug, info, error}; pub use structopt::StructOpt; pub use tokio::io::AsyncBufReadExt; +pub use tokio::select; pub use tokio::task; pub use tokio::time::Duration; pub use void::{self, Void, ResultVoidExt, ResultVoidErrExt}; @@ -39,4 +41,9 @@ pub use crate::types::*; pub use anyhow::Error as AE; pub use ErrorKind as EK; +pub const SLIP_END: u8 = 0o300; +pub const SLIP_ESC: u8 = 0o333; +pub const SLIP_ESC_END: u8 = 0o334; +pub const SLIP_ESC_ESC: u8 = 0o335; + pub fn default() -> T { Default::default() }