chiark / gitweb /
debug
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 6 Sep 2020 01:20:00 +0000 (02:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 6 Sep 2020 01:20:00 +0000 (02:20 +0100)
src/bin/server.rs
src/debugreader.rs
src/imports.rs
src/lib.rs
src/sse.rs

index a0b13954449b0b9d1b8556e2c0f5e4546ff01dcd..700a225e141f3460968067e746cb95fd3cdfe0e7 100644 (file)
@@ -53,7 +53,10 @@ fn updates<'r>(ctoken : InstanceAccess<ClientId>, gen: u64,
            -> impl response::Responder<'r> {
   let gen = Generation(gen);
   let iad = ctoken.i;
+  debug!("starting update stream {:?}", &iad);
+  let client = iad.ident;
   let content = sse::content(iad, gen)?;
+  let content = DebugReader(content, client);
   let content = response::Stream::chunked(content, 4096);
   const CTYPE : &str = "text/event-stream; charset=utf-8";
   let ctype = ContentType::parse_flexible(CTYPE).unwrap();
index bb905074d99e66164343ecdf77c4d07a1eb3d890..4eeb2707004d5a7378ccff4a2a0bdfc53f7811c6 100644 (file)
@@ -1,13 +1,16 @@
+
+use crate::imports::*;
+
 #[derive(Debug)]
-pub struct DebugReader<T : Read>(pub T);
+pub struct DebugReader<T : Read>(pub T, pub ClientId);
 
 impl<T : Read> Read for DebugReader<T> {
   fn read(&mut self, buf: &mut [u8]) -> Result<usize,io::Error> {
     let l = buf.len();
-    eprintln!("DebugReader({:?}).read()...", l);
+    trace!("{} read({})...", &self.1, l);
     let r = self.0.read(buf);
-    eprintln!("DebugReader({:?}).read() = {:?} {:?}", l, &r,
-              r.as_ref().map(|&r| str::from_utf8(&buf[0..r])));
+    debug!("{} read({}) = {:?} {:?}", &self.1, l, &r,
+           r.as_ref().map(|&r| str::from_utf8(&buf[0..r])));
     r
   }
 }
index ffd33a8dfe7e0615b119ac7179908c9d3c5004d0..18b3d3a3f96635407c166383d365c401efcc852a 100644 (file)
@@ -85,6 +85,7 @@ pub use crate::mgmtchannel::*;
 pub use crate::api::{Lens,TransparentLens};
 pub use crate::utils::*;
 pub use crate::spec::*;
+pub use crate::debugreader::DebugReader;
 
 pub use nix::unistd::Uid;
 
index f1d151b3b768164796e8eff5efd7862ceee4b498..10699b8904a9d3884ff3a4fdb6a7d3dc6370a71f 100644 (file)
@@ -20,4 +20,5 @@ pub mod cmdlistener;
 pub mod commands;
 pub mod utils;
 pub mod mgmtchannel;
+pub mod debugreader;
 #[path="slotmap-slot-idx.rs"] pub mod slotmap_slot_idx;
index 0b923a916e9a6bb0cef693cbcd6f36ad2b6e395f..3fcaa06d541c7d6adab4f84cd562d71627e902c7 100644 (file)
@@ -59,7 +59,8 @@ impl Read for UpdateReader {
       let tu = next.for_transmit(self.client);
       // xxx handle overflow by allocating
       write!(buf, "data: ")?;
-      serde_json::to_writer(&mut buf, &tu)?;
+      serde_json::to_writer(&mut buf, &tu)
+        .map_err(|e| { error!("serde_json::to_write: {:?}", e); e })?;
       write!(buf, "\n\
                    id: {}\n\n",
              &self.to_send)?;