chiark / gitweb /
change type of IsResponseToClientOp
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 30 Sep 2020 22:14:40 +0000 (23:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 30 Sep 2020 22:14:40 +0000 (23:14 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/api.rs
src/cmdlistener.rs
src/global.rs
src/updates.rs

index 41b716e3579743e85afc920ce091673433f2f6b5..7ef93980f21a83a887f6c3c9ac4e7153932958e5 100644 (file)
@@ -141,7 +141,7 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
     },
     Ok((update, logents)) => {
       let mut buf = PrepareUpdatesBuffer::new(g,
-               IsResponseToClientOp::Predictable((client, form.cseq)),
+          Some((WhatResponseToClientOp::Predictable, client, form.cseq)),
                                               Some(1 + logents.len()));
       
       buf.piece_update(piece, update, &lens);
index bd9f391c685794ccc62b6e6848f453241ed1d5b0..95d93170cffc44c987262ad9fe4009ddff82bd7f 100644 (file)
@@ -370,8 +370,7 @@ impl UpdateHandler {
       },
       Online => {
         let estimate = updates.pcs.len() + updates.log.len();
-        let irc = IsResponseToClientOp::No;
-        let mut buf = PrepareUpdatesBuffer::new(g, irc, Some(estimate));
+        let mut buf = PrepareUpdatesBuffer::new(g, None, Some(estimate));
         for (upiece, uuop) in updates.pcs {
           let lens = TransparentLens { };
           buf.piece_update(upiece, uuop, &lens);
@@ -387,8 +386,7 @@ impl UpdateHandler {
     use UpdateHandler::*;
     match self {
       Bulk(bulk) => {
-        let irc = IsResponseToClientOp::No;
-        let mut buf = PrepareUpdatesBuffer::new(g, irc, None);
+        let mut buf = PrepareUpdatesBuffer::new(g, None, None);
         for (upiece, uuop) in bulk.pieces {
           let lens = TransparentLens { };
           buf.piece_update(upiece, uuop, &lens);
index 710efa3e96bf8ec0999a7dba34314f4ab36b4fd3..1389881cdd81d1e2b1ad3d1928de455728d5859d 100644 (file)
@@ -448,8 +448,7 @@ impl InstanceGuard<'_> {
 
       let lens = TransparentLens { };
       let estimate = updated_pieces.len() + 1;
-      let mut buf = PrepareUpdatesBuffer::new(
-        self, IsResponseToClientOp::No , Some(estimate));
+      let mut buf = PrepareUpdatesBuffer::new(self, None , Some(estimate));
       for &piece in &updated_pieces {
         buf.piece_update(piece, PieceUpdateOp::Modify(()), &lens);
       }
index 77ba09124c1358b6e96b629f6ed22a2b9a122a2f..72d792c8c66c554433cf0ddacc4d5f122e62a970 100644 (file)
@@ -42,7 +42,7 @@ pub struct PreparedUpdate {
 #[derive(Debug)]
 pub enum PreparedUpdateEntry {
   Piece {
-    by_client: IsResponseToClientOp<(ClientId, ClientSequence)>,
+    by_client: IsResponseToClientOp,
     piece : VisiblePieceId,
     op : PieceUpdateOp<PreparedPieceState>,
   },
@@ -239,28 +239,32 @@ impl<NS> PieceUpdateOp<NS> {
 pub struct PrepareUpdatesBuffer<'r> {
   g : &'r mut Instance,
   us : Vec<PreparedUpdateEntry>,
-  by_client : IsResponseToClientOp<(ClientId, ClientSequence)>,
+  by_client : IsResponseToClientOp,
   gen : Option<Generation>,
 }
 
+/// In PROTOCOL.md terms, None is a Server update
+type IsResponseToClientOp = Option<(
+  WhatResponseToClientOp,
+  ClientId,
+  ClientSequence,
+)>;
 #[derive(Debug,Copy,Clone)]
-pub enum IsResponseToClientOp<T> {
-  /// In PROTOCOL.md terms, a Server update
-  No,
+pub enum WhatResponseToClientOp {
   /// In PROTOCOL.md terms, a Client update
-  Predictable(T),
+  Predictable,
   /// In PROTOCOL.md terms, a Client update which also updates
   /// the visible piece image (which is just server-controlled).
-  UpdateSvg(T),
+  UpdateSvg,
   /// In PROTOCOL.md terms, a Client update which results in
   /// an immediate Server update.  When the client knows this
   /// is going to happen it can help the user avoid conflicts.
-  Unpredictable(T),
+  Unpredictable,
 }
 
 impl<'r> PrepareUpdatesBuffer<'r> {
   pub fn new(g: &'r mut Instance,
-             by_client: IsResponseToClientOp<(ClientId, ClientSequence)>,
+             by_client: IsResponseToClientOp,
              estimate: Option<usize>) -> Self
   {
     let us = estimate.map_or(vec![], Vec::with_capacity);
@@ -280,7 +284,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   }
 
   fn new_for_error(ig: &'r mut Instance) -> Self {
-    Self::new(ig, IsResponseToClientOp::No, Some(1))
+    Self::new(ig, None, Some(1))
   }
   pub fn piece_report_error(ig: &mut Instance,
                             error: PieceOpError, piece: PieceId,
@@ -314,7 +318,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   fn piece_update_fallible(&mut self, piece: PieceId,
                            update: PieceUpdateOp<()>,
                            lens: &dyn Lens) -> PreparedUpdateEntry {
-    type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>;
+    type WRC = WhatResponseToClientOp;
 
     let gen = self.gen();
     let gs = &mut self.g.gs;
@@ -327,8 +331,8 @@ impl<'r> PrepareUpdatesBuffer<'r> {
         gs.max_z.update_max(pc.zlevel.z);
 
         if let Some(new_lastclient) = match self.by_client {
-          IRC::Predictable((tclient,_)) |
-          IRC::UpdateSvg((tclient,_))
+          Some((WRC::Predictable,tclient,_)) |
+          Some((WRC::UpdateSvg,  tclient,_))
             => if tclient == pc.lastclient { None } else { Some(tclient) }
           _ => Some(Default::default()),
         } {
@@ -412,19 +416,15 @@ impl<'r> Drop for PrepareUpdatesBuffer<'r> {
 
 // ---------- for traansmission ----------
 
-type IRC = IsResponseToClientOp<(ClientId, ClientSequence)>;
+type WRC = WhatResponseToClientOp;
 
 impl PreparedUpdate {
-  fn is_client(by_client: &IsResponseToClientOp<(ClientId, ClientSequence)>,
+  fn is_client(by_client: &IsResponseToClientOp,
                ref_client: ClientId) -> Option<ClientSequence> {
-    use IsResponseToClientOp::*;
-    let &(c,cseq) = match by_client {
-      Predictable  (x) => x,
-      UpdateSvg    (x) => x,
-      Unpredictable(x) => x,
-      No               => return None,
-    };
-    if c == ref_client { Some(cseq) } else { None }
+    match by_client {
+      &Some((_,c,cseq)) if c == ref_client => Some(cseq),
+      _ => None,
+    }
   }
 
   pub fn for_transmit(&self, dest : ClientId) -> TransmitUpdate {
@@ -443,16 +443,15 @@ impl PreparedUpdate {
             Piece,
           };
           let ftg = if let Some(cseq) = Self::is_client(&by_client, dest) {
-            match by_client {
-              IRC::Predictable(_) => FTG::Recorded(cseq, None),
-              IRC::UpdateSvg(_) => FTG::Recorded(cseq, ns()),
-              IRC::Unpredictable(_) => if let Some(ns) = ns() {
+            match by_client.unwrap().0 {
+              WRC::Predictable => FTG::Recorded(cseq, None),
+              WRC::UpdateSvg => FTG::Recorded(cseq, ns()),
+              WRC::Unpredictable => if let Some(ns) = ns() {
                 FTG::Exactly(TUE::RecordedUnpredictable { piece, cseq, ns })
               } else {
                 error!("internal error: for_transmit PreparedUpdateEntry::Piece with RecordedUnpredictable but PieceOp no NS");
                 FTG::Piece
               }
-              _ => unreachable!(),
             }
           } else {
             FTG::Piece