use rusteron_client::*;
use rusteron_media_driver::testing::EmbeddedDriver;
use std::thread::sleep;
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let (dir, _embedded) = match std::env::var("AERON_DIR") {
Ok(dir) => (dir, None),
Err(_) => {
let driver = EmbeddedDriver::launch()?;
let ctx = AeronContext::new()?;
ctx.set_dir(&cformat!("{}", driver.dir()))?;
let aeron = Aeron::new(&ctx)?;
aeron.start()?;
let publication = aeron
.async_add_publication(AERON_IPC_STREAM, 77)?
.poll_blocking(Duration::from_secs(5))?;
let subscription = aeron
.async_add_subscription(AERON_IPC_STREAM, 77, Handlers::NONE, Handlers::NONE)?
.poll_blocking(Duration::from_secs(5))?;
for _ in 0..100 {
let _ = publication.offer(b"stats-traffic");
subscription.poll_fn(|_, _| {}, 16)?;
}
let _ = aeron
.async_add_publication(c"aeron:udp?endpoint=bad-host:0|interface=1.2.3.4.5", 78)
.and_then(|p| p.poll_blocking(Duration::from_secs(1)));
sleep(Duration::from_millis(200));
let dir = driver.dir().to_string();
(dir, Some((aeron, publication, subscription, driver)))
}
};
let cnc = AeronCnc::open(&cformat!("{dir}"))?;
println!(
"CnC version {}; driver heartbeat age {} ms",
cnc.get_constants()?.cnc_version,
{
let now = Aeron::epoch_clock();
now - cnc.get_to_driver_heartbeat_ms()?
}
);
println!("\n===== counters =====");
cnc.counters_reader()
.foreach_counter_fn(|value, id, type_id, _key, label| {
println!("{id:>4} (type {type_id:>3}): {value:>16} — {label}");
});
println!("\n===== distinct errors =====");
let count = cnc.error_log_read_fn(
|observation_count, first_ts, last_ts, error| {
println!("{observation_count:>4}x [{first_ts} .. {last_ts}] {error}");
},
0, );
println!("({count} distinct error(s))");
println!("\n===== loss report =====");
let entries = cnc.loss_reporter_read_fn(
|observations, total_bytes, first_ts, last_ts, session_id, stream_id, channel, source| {
println!(
"{observations:>4}x {total_bytes:>10}B [{first_ts} .. {last_ts}] session {session_id} stream {stream_id} {channel} <- {source}"
);
},
)?;
println!("({entries} loss entrie(s))");
if let Some((_aeron, _publication, _subscription, driver)) = _embedded {
drop(driver); }
Ok(())
}