chiark / gitweb /
client: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 23:50:53 +0000 (00:50 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 25 Jul 2021 23:50:53 +0000 (00:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/prelude.rs

index f01bb6fde8863eb586ef06fd2441c40a5e95f40d..3abfc1959b8d2a2fa13563ac939a007ce24ba0a6 100644 (file)
@@ -35,16 +35,26 @@ async fn run_client<C>(ic: InstanceConfig, hclient: Arc<hyper::Client<C>>)
     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]
index b1d79383920bdb4e19649ccb01bbfea13f589cfb..4198ed9818b96ab45112e2a48b28000e300dba6f 100644 (file)
@@ -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>() -> T { Default::default() }