Merge pull request #7 from Trivernis/develop

Add more logging
pull/9/head
Julius Riegel 3 years ago committed by GitHub
commit 744a40cb8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
Cargo.lock generated

@ -148,7 +148,7 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.4.1" version = "0.4.2"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"log", "log",

@ -1,6 +1,6 @@
[package] [package]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.4.1" version = "0.4.2"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"

@ -69,6 +69,7 @@ impl Event {
/// Reads an event message /// Reads an event message
pub async fn from_async_read<R: AsyncRead + Unpin>(reader: &mut R) -> Result<Self> { pub async fn from_async_read<R: AsyncRead + Unpin>(reader: &mut R) -> Result<Self> {
let length = reader.read_u32().await?; let length = reader.read_u32().await?;
log::trace!("Parsing event of length {}", length);
let mut data = vec![0u8; length as usize]; let mut data = vec![0u8; length as usize];
reader.read_exact(&mut data).await?; reader.read_exact(&mut data).await?;
let event = rmp_serde::from_read(&data[..])?; let event = rmp_serde::from_read(&data[..])?;

@ -32,6 +32,7 @@ impl IPCClient {
); );
let handler = Arc::new(self.handler); let handler = Arc::new(self.handler);
let namespaces = Arc::new(self.namespaces); let namespaces = Arc::new(self.namespaces);
log::debug!("IPC client connected to {}", address);
tokio::spawn({ tokio::spawn({
let ctx = Context::clone(&ctx); let ctx = Context::clone(&ctx);

@ -21,9 +21,11 @@ async fn handle_connection(
ctx: Context, ctx: Context,
) { ) {
while let Ok(event) = Event::from_async_read(&mut read_half).await { while let Ok(event) = Event::from_async_read(&mut read_half).await {
log::debug!("Received {:?}:{} event", event.namespace(), event.name());
// check if the event is a reply // check if the event is a reply
if let Some(ref_id) = event.reference_id() { if let Some(ref_id) = event.reference_id() {
// get the listener for replies // get the listener for replies
log::trace!("Event is response to {}", ref_id);
if let Some(sender) = ctx.get_reply_sender(ref_id).await { if let Some(sender) = ctx.get_reply_sender(ref_id).await {
// try sending the event to the listener for replies // try sending the event to the listener for replies
if let Err(event) = sender.send(event) { if let Err(event) = sender.send(event) {
@ -31,11 +33,14 @@ async fn handle_connection(
} }
continue; continue;
} }
log::trace!("No response listener found for event. Passing to regular listener.");
} }
if let Some(namespace) = event.namespace().clone().and_then(|n| namespaces.get(&n)) { if let Some(namespace) = event.namespace().clone().and_then(|n| namespaces.get(&n)) {
log::trace!("Passing event to namespace listener");
let handler = Arc::clone(&namespace.handler); let handler = Arc::clone(&namespace.handler);
handle_event(Context::clone(&ctx), handler, event); handle_event(Context::clone(&ctx), handler, event);
} else { } else {
log::trace!("Passing event to global listener");
handle_event(Context::clone(&ctx), Arc::clone(&handler), event); handle_event(Context::clone(&ctx), Arc::clone(&handler), event);
} }
} }

@ -27,6 +27,7 @@ impl IPCServer {
let handler = Arc::new(self.handler); let handler = Arc::new(self.handler);
let namespaces = Arc::new(self.namespaces); let namespaces = Arc::new(self.namespaces);
let data = Arc::new(RwLock::new(self.data)); let data = Arc::new(RwLock::new(self.data));
log::debug!("IPC server listening on {}", address);
while let Ok((stream, _)) = listener.accept().await { while let Ok((stream, _)) = listener.accept().await {
let handler = Arc::clone(&handler); let handler = Arc::clone(&handler);

@ -30,6 +30,8 @@ impl StreamEmitter {
res_id: Option<u64>, res_id: Option<u64>,
) -> Result<EmitMetadata> { ) -> Result<EmitMetadata> {
let data_bytes = rmp_serde::to_vec(&data)?; let data_bytes = rmp_serde::to_vec(&data)?;
log::debug!("Emitting event {:?}:{}", namespace, event);
let event = if let Some(namespace) = namespace { let event = if let Some(namespace) = namespace {
Event::with_namespace(namespace.to_string(), event.to_string(), data_bytes, res_id) Event::with_namespace(namespace.to_string(), event.to_string(), data_bytes, res_id)
} else { } else {
@ -38,6 +40,7 @@ impl StreamEmitter {
let event_bytes = event.to_bytes()?; let event_bytes = event.to_bytes()?;
{ {
log::trace!("Writing {} bytes", event_bytes.len());
let mut stream = self.stream.lock().await; let mut stream = self.stream.lock().await;
(*stream).write_all(&event_bytes[..]).await?; (*stream).write_all(&event_bytes[..]).await?;
} }

Loading…
Cancel
Save