chiark / gitweb /
break out Ipif::next_frame
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Aug 2021 23:59:27 +0000 (00:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Aug 2021 23:59:27 +0000 (00:59 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
client/client.rs
src/ipif.rs

index 8597cfd3ba2264ccff8b81dfafe149e7f5286e80..8e58c7c2a5f9dad9d6c943083b8aa2a69372ec42 100644 (file)
@@ -221,12 +221,10 @@ async fn run_client<C:HCC>(
           let _ = tx_queue.pop_front();
         },
 
-        data = ipif.tx.next_segment(),
+        data = Ipif::next_frame(&mut ipif.tx),
         if tx_queue.is_empty() =>
         {
-          let data = (||{
-            data?.ok_or_else(|| io::Error::from(io::ErrorKind::UnexpectedEof))
-          })().context("read from ipif")?;
+          let data = data?;
           //eprintln!("data={:?}", DumpHex(&data));
 
           match check1(Slip2Mime, ic.mtu, &data, |header| {
index b98249b3a75332a38ffb446343117b628b8ee2a8..e6762add7f61f88048fa74ea7ca6d5e00497e27c 100644 (file)
@@ -4,8 +4,10 @@
 
 use crate::prelude::*;
 
+type Tx = t_io::Split<t_io::BufReader<t_proc::ChildStdout>>;
+
 pub struct Ipif {
-  pub tx: t_io::Split<t_io::BufReader<t_proc::ChildStdout>>,
+  pub tx: Tx,
   pub rx: t_proc::ChildStdin,
   stderr_task: JoinHandle<io::Result<()>>,
   child: t_proc::Child,
@@ -69,4 +71,12 @@ impl Ipif {
 
     drop(self.tx);
   }
+
+  #[throws(AE)]
+  pub async fn next_frame(tx: &mut Tx) -> Vec<u8> {
+    let data = tx.next_segment().await;
+    (||{
+      data?.ok_or_else(|| io::Error::from(io::ErrorKind::UnexpectedEof))
+    })().context("read from ipif")?
+  }
 }