From 1ff87bd03b2dcf06080c195bd812d5e36aed809e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 22 Aug 2021 00:59:27 +0100 Subject: [PATCH] break out Ipif::next_frame Signed-off-by: Ian Jackson --- client/client.rs | 6 ++---- src/ipif.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client/client.rs b/client/client.rs index 8597cfd..8e58c7c 100644 --- a/client/client.rs +++ b/client/client.rs @@ -221,12 +221,10 @@ async fn run_client( 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| { diff --git a/src/ipif.rs b/src/ipif.rs index b98249b..e6762ad 100644 --- a/src/ipif.rs +++ b/src/ipif.rs @@ -4,8 +4,10 @@ use crate::prelude::*; +type Tx = t_io::Split>; + pub struct Ipif { - pub tx: t_io::Split>, + pub tx: Tx, pub rx: t_proc::ChildStdin, stderr_task: JoinHandle>, child: t_proc::Child, @@ -69,4 +71,12 @@ impl Ipif { drop(self.tx); } + + #[throws(AE)] + pub async fn next_frame(tx: &mut Tx) -> Vec { + let data = tx.next_segment().await; + (||{ + data?.ok_or_else(|| io::Error::from(io::ErrorKind::UnexpectedEof)) + })().context("read from ipif")? + } } -- 2.30.2