Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When launched with a file path, the viewer will now still listen for TCP connections #6951

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 33 additions & 16 deletions crates/top/rerun/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ fn run_impl(
) -> anyhow::Result<()> {
#[cfg(feature = "native_viewer")]
let profiler = profiler(&args);
let mut is_another_viewer_running = false;

#[cfg(feature = "native_viewer")]
let startup_options = {
Expand Down Expand Up @@ -918,20 +919,7 @@ fn run_impl(
};

// Where do we get the data from?
let rx: Vec<Receiver<LogMsg>> = if args.url_or_paths.is_empty() {
#[cfg(feature = "server")]
{
let server_options = re_sdk_comms::ServerOptions {
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
quiet: false,
};
let rx = re_sdk_comms::serve(&args.bind, args.port, server_options)?;
vec![rx]
}

#[cfg(not(feature = "server"))]
vec![]
} else {
let rx: Vec<Receiver<LogMsg>> = {
let data_sources = args
.url_or_paths
.iter()
Expand All @@ -957,10 +945,36 @@ fn run_impl(
}
}

data_sources
let mut rxs = data_sources
.into_iter()
.map(|data_source| data_source.stream(None))
.collect::<Result<Vec<_>, _>>()?
.collect::<Result<Vec<_>, _>>()?;

#[cfg(feature = "server")]
{
// Check if there is already a viewer running
// and if so, send the data to it.
use std::net::TcpStream;
let connect_addr = std::net::SocketAddr::new(args.bind.parse().unwrap(), args.port);
if TcpStream::connect_timeout(&connect_addr, std::time::Duration::from_secs(1)).is_ok()
{
re_log::info!(
addr = %connect_addr,
"A process is already listening at this address. Assuming it's a Rerun Viewer."
);
is_another_viewer_running = true;
} else {
let server_options = re_sdk_comms::ServerOptions {
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
quiet: false,
};
let tcp_listener: Receiver<LogMsg> =
re_sdk_comms::serve(&args.bind, args.port, server_options)?;
rxs.push(tcp_listener);
}
}

rxs
};

// Now what do we do with the data?
Expand Down Expand Up @@ -1030,6 +1044,9 @@ fn run_impl(

return Ok(());
}
} else if is_another_viewer_running {
re_log::info!("Another viewer is already running, streaming data to it.");
Ok(())
} else {
#[cfg(feature = "native_viewer")]
return re_viewer::run_native_app(
Expand Down
Loading