Skip to content

Commit

Permalink
wip: tcp client event debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
beni69 committed Aug 1, 2023
1 parent 9622000 commit bfd9ee8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/examples/gpio_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ fn main() -> Result<()> {

log::info!("subscribe");
inp.subscribe(move |b| {
dbg!(b);
out.set(b)?;
dbg!(b);
Ok(())
})?;

Expand Down
9 changes: 8 additions & 1 deletion roblib/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ pub use crate::camloc::cmd::*;
pub use self::concrete::Concrete;

pub trait Command:
Serialize + DeserializeOwned + Into<Concrete> + From<Concrete> + Send + Sync + 'static
Serialize
+ DeserializeOwned
+ Into<Concrete>
+ From<Concrete>
+ Send
+ Sync
+ 'static
+ std::fmt::Debug
{
const PREFIX: char;
type Return: Serialize + DeserializeOwned + Send + Sync + 'static;
Expand Down
23 changes: 12 additions & 11 deletions server/src/transports/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! TCP wire format:
//! -> u32: message length, (u32: id, roblib::cmd::Concrete)
//! <- u32: message length, (u32: id, roblib::cmd::Concrete::Return)
//! <- u32: message length, (u32: id, roblib::event::ConcreteValue)
//! <- u32: message length, (u32: id, roblib::event::Event::Item)
use crate::{
cmd::execute_concrete, event_bus::sub::SubStatus, transports::SubscriptionId, Backends,
};
Expand Down Expand Up @@ -80,7 +80,7 @@ async fn handle_client(
match action {
Action::ClientMessage(n) => {
if n == 0 {
log::debug!("received 0 sized msg, investigating disconnect");
log::debug!("tcp: received 0 sized msg, investigating disconnect");
// give the socket some time to fully realize disconnect
tokio::time::sleep(Duration::from_millis(50)).await;
let r = stream.ready(Interest::READABLE | Interest::WRITABLE).await;
Expand All @@ -91,13 +91,14 @@ async fn handle_client(
}

len += n;
log::debug!(
"Thing::ClientMessage - n: {n}, len: {len}, mblen: {maybe_cmd_len:?}, buflen: {}",
buf.len()
);
// log::debug!(
// "Thing::ClientMessage - n: {n}, len: {len}, mblen: {maybe_cmd_len:?}, buflen: {}",
// buf.len()
// );

// not enough bytes to get command length
if len < HEADER {
log::debug!("read more header");
// log::debug!("read more header");
continue;
}

Expand All @@ -107,14 +108,14 @@ async fn handle_client(
let cmd = u32::from_be_bytes((&buf[..HEADER]).try_into().unwrap()) as usize;
// buf.resize(HEADER + cmd, 0);
maybe_cmd_len = Some(cmd);
log::debug!("header received, cmdlen: {cmd}");
// log::debug!("header received, cmdlen: {cmd}");
cmd
}
};

// not enough bytes to parse command, get some more
if len < HEADER + cmd_len {
log::debug!("read more command");
// log::debug!("read more command");
continue;
}

Expand All @@ -124,14 +125,14 @@ async fn handle_client(
match cmd {
cmd::Concrete::Subscribe(c) => {
let sub = SubscriptionId::Tcp(addr, id);
dbg!(&sub);
dbg!((&c, &sub));
if let Err(e) = robot.sub.send((c.0, sub, SubStatus::Subscribe)) {
log::error!("event bus sub error: {e}");
};
}
cmd::Concrete::Unsubscribe(c) => {
let unsub = SubscriptionId::Tcp(addr, id);
dbg!(&unsub);
dbg!((&c, &unsub));
if let Err(e) = robot.sub.send((c.0, unsub, SubStatus::Unsubscribe)) {
log::error!("event bus sub error: {e}");
};
Expand Down

1 comment on commit bfd9ee8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts

View all

base roland
aarch64-unknown-linux-gnu Download Download
aarch64-unknown-linux-musl Download Download
armv7-unknown-linux-gnueabihf Download Download
armv7-unknown-linux-musleabihf Download Download
x86_64-pc-windows-msvc Download Download
x86_64-unknown-linux-gnu Download Download
x86_64-unknown-linux-musl Download Download

Please sign in to comment.