chiark / gitweb /
rx queue add delimiters
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 23:44:12 +0000 (00:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 23:44:12 +0000 (00:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/queue.rs

index 937d35f8ca6abca72d053624909d617fb9be8690..95d473011bf638e0a13456227b37e52dda337039 100644 (file)
@@ -193,7 +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: Queue<Box<[u8]>> = default();
+  let mut rx_queue: FrameQueue = default();
 
   // xxx check that ic settings are all honoured
 
@@ -270,7 +270,6 @@ async fn run_client<C:HCC>(
               Ok(())
             }, |e| error!("{} #{}: rx discarding: {}", &ic, req_num, e));
           
-            dbg!(&rx_queue);
           }
         }
       }
index f821eb0c36111b8b8a92069d222b92642c116a30..ba1d4ffedf76bbf55056e6e2b3824ed972000258 100644 (file)
@@ -11,6 +11,11 @@ pub struct Queue<E> {
   queue: VecDeque<E>,
 }
 
+#[derive(Default,Debug,Clone)]
+pub struct FrameQueue {
+  queue: Queue<Cervine<'static, Box<[u8]>, [u8]>>,
+}
+
 impl<E> Debug for Queue<E> where E: AsRef<[u8]> {
   #[throws(fmt::Error)]
   fn fmt(&self, f: &mut fmt::Formatter) {
@@ -33,7 +38,18 @@ impl<E> Queue<E> where E: AsRef<[u8]> {
   pub fn is_empty(&self) -> bool { self.content == 0 }
 }
 
-impl<E> Extend<E> for Queue<E> where E: AsRef<[u8]> {
+impl FrameQueue {
+  pub fn push<B: Into<Box<[u8]>>>(&mut self, b: B) {
+    self.push_(b.into());
+  }
+  pub fn push_(&mut self, b: Box<[u8]>) {
+    self.queue.push_(Cervine::Owned(b));
+    self.queue.push_(Cervine::Borrowed(&SLIP_END_SLICE));
+  }
+  pub fn is_empty(&self) -> bool { self.queue.is_empty() }
+}
+
+impl<E> Extend<E> for FrameQueue where E: Into<Box<[u8]>> {
   fn extend<I>(&mut self, it: I)
   where I: IntoIterator<Item=E>
   {
@@ -59,3 +75,9 @@ impl<E> hyper::body::Buf for Queue<E> where E: AsRef<[u8]> {
     }
   }
 }
+
+impl hyper::body::Buf for FrameQueue {
+  fn remaining(&self) -> usize { self.queue.remaining() }
+  fn chunk(&self) -> &[u8] { self.queue.chunk() }
+  fn advance(&mut self, cnt: usize) { self.queue.advance(cnt) }
+}