Skip to content

Commit

Permalink
impl fmt::Debug for re_sdk_comms::Client
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Jul 25, 2023
1 parent 094b7c4 commit 891414b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
15 changes: 9 additions & 6 deletions crates/re_log_encoding/src/file_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ impl FileSink {

let join_handle = std::thread::Builder::new()
.name("file_writer".into())
.spawn(move || {
while let Ok(Some(log_msg)) = rx.recv() {
if let Err(err) = encoder.append(&log_msg) {
re_log::error!("Failed to save log stream to {path:?}: {err}");
return;
.spawn({
let path = path.clone();
move || {
while let Ok(Some(log_msg)) = rx.recv() {
if let Err(err) = encoder.append(&log_msg) {
re_log::error!("Failed to save log stream to {path:?}: {err}");
return;
}
}
re_log::debug!("Log stream saved to {path:?}");
}
re_log::debug!("Log stream saved to {path:?}");
})
.map_err(FileSinkError::SpawnThread)?;

Expand Down
13 changes: 1 addition & 12 deletions crates/re_sdk/src/log_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ impl MemorySinkStorage {
// ----------------------------------------------------------------------------

/// Stream log messages to a Rerun TCP server.
#[derive(Debug)]
pub struct TcpSink {
// used for Debug only
addr: std::net::SocketAddr,
client: re_sdk_comms::Client,
}

Expand All @@ -196,7 +195,6 @@ impl TcpSink {
#[inline]
pub fn new(addr: std::net::SocketAddr) -> Self {
Self {
addr,
client: re_sdk_comms::Client::new(addr),
}
}
Expand All @@ -218,12 +216,3 @@ impl LogSink for TcpSink {
self.client.drop_if_disconnected();
}
}

impl fmt::Debug for TcpSink {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// The `client` field has no printable state
f.debug_struct("TcpSink")
.field("addr", &self.addr)
.finish_non_exhaustive()
}
}
15 changes: 14 additions & 1 deletion crates/re_sdk_comms/src/buffered_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{net::SocketAddr, thread::JoinHandle};
use std::{fmt, net::SocketAddr, thread::JoinHandle};

use crossbeam::channel::{select, Receiver, Sender};

Expand Down Expand Up @@ -47,6 +47,9 @@ pub struct Client {
encode_join: Option<JoinHandle<()>>,
send_join: Option<JoinHandle<()>>,
drop_join: Option<JoinHandle<()>>,

/// Only used for diagnostics, not for communication after `new()`.
addr: SocketAddr,
}

impl Client {
Expand Down Expand Up @@ -105,6 +108,7 @@ impl Client {
encode_join: Some(encode_join),
send_join: Some(send_join),
drop_join: Some(drop_join),
addr,
}
}

Expand Down Expand Up @@ -164,6 +168,15 @@ impl Drop for Client {
}
}

impl fmt::Debug for Client {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// The other fields are all channels and join handles, so they are not usefully printable.
f.debug_struct("Client")
.field("addr", &self.addr)
.finish_non_exhaustive()
}
}

// We drop messages in a separate thread because the PyO3 + Arrow memory model
// means in some cases these messages actually store pointers back to
// python-managed memory. We don't want to block our send-thread waiting for the
Expand Down

0 comments on commit 891414b

Please sign in to comment.