chiark / gitweb /
sse: Move to daemon
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 11 Jul 2021 10:56:37 +0000 (11:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 19 Mar 2022 16:01:02 +0000 (16:01 +0000)
We might perhaps be going to want this to use some macros from
our web framework.

(Commit originally intended for Rocket 0.5 branch.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/main.rs
daemon/sse.rs [moved from src/sse.rs with 87% similarity]
src/lib.rs
src/prelude.rs
src/updates.rs

index 8d8da1bf727bb5fc68edb0169973f77aa342cc6f..2dcf57572fba71031a6b0d78ad831dcbbbc95040 100644 (file)
@@ -11,6 +11,7 @@ pub mod imports;
 pub mod api;
 pub mod cmdlistener;
 pub mod session;
+pub mod sse;
 
 pub use rocket::http::Status;
 pub use rocket::http::{ContentType, RawStr};
similarity index 87%
rename from src/sse.rs
rename to daemon/sse.rs
index 8f33e5a20a0c797a4b15aae658b425797e1f2dfa..4e1dc387f047ab653e27eec19471c59feb841e9e 100644 (file)
@@ -5,18 +5,10 @@
 #![allow(clippy::while_let_loop)]
 #![allow(clippy::blocks_in_if_conditions)]
 
-use crate::prelude::*;
-
-use vecdeque_stableix::Offset as StableIndexOffset;
-use std::ops::Neg;
+use otter::prelude::*;
 
 // ---------- basic definitions ----------
 
-#[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd)]
-#[derive(Serialize,Deserialize)]
-#[serde(transparent)]
-pub struct UpdateId(i64);
-
 const UPDATE_READER_SIZE: usize = 1024*32;
 const UPDATE_MAX_FRAMING_SIZE: usize = 200;
 const UPDATE_KEEPALIVE: Duration = Duration::from_secs(14);
@@ -224,36 +216,6 @@ impl Read for UpdateReader {
   }
 }
 
-// ---------- support implementation ----------
-
-impl Neg for UpdateId {
-  type Output = Self;
-  fn neg(self) -> Self { UpdateId(-self.0) }
-}
-
-impl Display for UpdateId {
-  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
-    Display::fmt(&self.0, f)
-  }
-}
-
-impl Bounded for UpdateId {
-  fn max_value() -> Self { UpdateId(Bounded::max_value()) }
-  fn min_value() -> Self { UpdateId(Bounded::min_value()) }
-}
-
-impl StableIndexOffset for UpdateId {
-  fn try_increment(&mut self) -> Option<()> { self.0.try_increment() }
-  fn try_decrement(&mut self) -> Option<()> { self.0.try_decrement() }
-  fn index_input(&self, input: Self) -> Option<usize> {
-    self.0.index_input(input.0)
-  }
-  fn index_output(&self, inner: usize) -> Option<Self> {
-    self.0.index_output(inner).map(UpdateId)
-  }
-  fn zero() -> Self { UpdateId(0) }
-}
-
 // ---------- entrypoint for dribbling the http response ----------
 
 #[throws(Fatal)]
index fbeacecb8d04661284d47ae768707bfdd966043e..232001c092527cd2e3e177ff24e485d8689f6595 100644 (file)
@@ -35,7 +35,6 @@ pub mod pieces;
 pub mod progress;
 pub mod shapelib;
 pub mod spec;
-pub mod sse;
 pub mod termprogress;
 pub mod timedfd;
 pub mod tz;
index 1db1ef269167c69f97c968fab7151ec048d5f68e..94bbb63fbe93a59e38b5851f3896e5cf48319cc4 100644 (file)
@@ -104,6 +104,7 @@ pub use thiserror::Error;
 pub use unicase::UniCase;
 pub use url::Url;
 pub use vecdeque_stableix::Deque as StableIndexVecDeque;
+pub use vecdeque_stableix::Offset as StableIndexOffset;
 pub use void::{unreachable, Void, ResultVoidExt, ResultVoidErrExt};
 pub use crate::imports::zipfile::{self, read::ZipFile, result::ZipError};
 
@@ -162,7 +163,6 @@ pub use crate::shapelib::{LibraryLoadError};
 pub use crate::slotmap_slot_idx::*;
 pub use crate::spec::*;
 pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon};
-pub use crate::sse;
 pub use crate::toml_de;
 pub use crate::timedfd::*;
 pub use crate::termprogress;
index 69a3ff07f3a8cd1e0e36e1d78f57087b2d0895bf..daa2af625dc1afbcb9c55956511cccc3fbda0b92 100644 (file)
@@ -6,6 +6,8 @@
 
 use crate::prelude::*;
 
+use std::ops::Neg;
+
 #[path="movehist.rs"] pub mod movehist;
 
 #[allow(non_camel_case_types)] type TUE_P<'u> = TransmitUpdateEntry_Piece<'u>;
@@ -14,6 +16,11 @@ use crate::prelude::*;
 
 // ---------- newtypes, type aliases, basic definitions ----------
 
+#[derive(Copy,Clone,Debug,Eq,PartialEq,Ord,PartialOrd)]
+#[derive(Serialize,Deserialize)]
+#[serde(transparent)]
+pub struct UpdateId(i64);
+
 pub type RawClientSequence = u64;
 
 #[derive(Debug,Copy,Clone,Eq,PartialEq,Deserialize,Serialize)]
@@ -37,7 +44,7 @@ pub struct ExecuteGameChangeUpdates {
 // ---------- prepared updates, queued in memory ----------
 
 pub type PlayerUpdatesLog =
-  StableIndexVecDeque<Arc<PreparedUpdate>,sse::UpdateId>;
+  StableIndexVecDeque<Arc<PreparedUpdate>,UpdateId>;
 
 #[derive(Debug)]
 pub struct PlayerUpdates {
@@ -337,6 +344,36 @@ pub fn log_did_to_piece(ioccults: &IOccults, goccults: &GameOccults,
   log_did_to_piece_whoby(ioccults,goccults,by_gpl,gpc,ipc,did)?.0
 }
 
+// ---------- support implementation ----------
+
+impl Neg for UpdateId {
+  type Output = Self;
+  fn neg(self) -> Self { UpdateId(-self.0) }
+}
+
+impl Display for UpdateId {
+  fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+    Display::fmt(&self.0, f)
+  }
+}
+
+impl Bounded for UpdateId {
+  fn max_value() -> Self { UpdateId(Bounded::max_value()) }
+  fn min_value() -> Self { UpdateId(Bounded::min_value()) }
+}
+
+impl StableIndexOffset for UpdateId {
+  fn try_increment(&mut self) -> Option<()> { self.0.try_increment() }
+  fn try_decrement(&mut self) -> Option<()> { self.0.try_decrement() }
+  fn index_input(&self, input: Self) -> Option<usize> {
+    self.0.index_input(input.0)
+  }
+  fn index_output(&self, inner: usize) -> Option<Self> {
+    self.0.index_output(inner).map(UpdateId)
+  }
+  fn zero() -> Self { UpdateId(0) }
+}
+
 // ---------- prepared updates, queued in memory ----------
 
 pub struct PlayerUpdatesBuildContext {