chiark / gitweb /
use queue
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 18:40:04 +0000 (19:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 18:40:04 +0000 (19:40 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/prelude.rs
src/queue.rs

index 46d86095ad6fd40861850a0dba777e42d844257d..1af2d305302586334600bd0d5d301342b9d7c5fd 100644 (file)
@@ -193,13 +193,7 @@ async fn run_client<C:HCC>(
   let mut reqs: Vec<OutstandingRequest>
     = Vec::with_capacity(ic.max_requests_outstanding.sat());
 
-  let mut rx_queue: VecDeque<Box<[u8]>> = default();
-  #[derive(Debug)]
-  enum RxState {
-    Frame(Cursor<Box<u8>>),
-    End,
-  }
-  let mut rx_current: Option<RxState> = None;
+  let mut rx_queue: Queue = default();
 
   // xxx check that ic settings are all honoured
 
@@ -262,7 +256,7 @@ async fn run_client<C:HCC>(
               Ok(())
             }, |e| error!("{} #{}: rx discarding: {}", &ic, req_num, e));
           
-            dbg!(&rx_queue.len());
+            dbg!(&rx_queue.remaining());
             rx_queue = default(); // xxx
           }
         }
index fd3c50b6afeba0187662f9dd39a8382aa5432c51..c9c11bef73d8e61f492d62e7b15087fc4e09ed08 100644 (file)
@@ -45,6 +45,7 @@ pub use void::{self, Void, ResultVoidExt, ResultVoidErrExt};
 
 pub use crate::config::{self, InstanceConfig, u32Ext as _};
 pub use crate::utils::*;
+pub use crate::queue::*;
 pub use crate::reporter::*;
 pub use crate::types::*;
 pub use crate::slip::*;
index 41691afce05e4bd839a0f9123419a3a455d68f3b..a7e0bb51fa2f4ba7e67e73242f990df069b91009 100644 (file)
@@ -17,12 +17,20 @@ impl Queue {
   }
   pub fn push_(&mut self, b: Box<[u8]>) {
     let l = b.len();
-    self.push(b);
+    self.queue.push_back(b);
     self.content += l;
   }
   pub fn is_empty(&self) -> bool { self.content == 0 }
 }
 
+impl<B> Extend<B> for Queue where B: Into<Box<[u8]>> {
+  fn extend<I>(&mut self, it: I)
+  where I: IntoIterator<Item=B>
+  {
+    for b in it { self.push(b) }
+  }
+}
+
 impl hyper::body::Buf for Queue {
   fn remaining(&self) -> usize { self.content }
   fn chunk(&self) -> &[u8] {