diff --git a/src/main.rs b/src/main.rs index 85f4383..650827c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -67,13 +67,15 @@ async fn main() { }); } - // 5️⃣ Spawn PTP client task + // 5️⃣ Spawn PTP client thread (blocking, not async) { let ptp_state = ltc_state.clone(); let config_clone = config_arc.clone(); - tokio::spawn(async move { - println!("🚀 PTP task launched"); - start_ptp_client(ptp_state, config_clone).await; + thread::spawn(move || { + println!("🚀 PTP thread launched"); + // Create a new tokio runtime for this thread + let rt = tokio::runtime::Runtime::new().unwrap(); + rt.block_on(start_ptp_client(ptp_state, config_clone)); }); } diff --git a/src/ptp.rs b/src/ptp.rs index 8aaaef7..25eaa25 100644 --- a/src/ptp.rs +++ b/src/ptp.rs @@ -1,6 +1,6 @@ use crate::config::Config; use crate::sync_logic::LtcState; -use rand::thread_rng; +use rand::{rngs::StdRng, SeedableRng}; use statime::{ config::{ AcceptAnyMaster, ClockIdentity, DelayMechanism, InstanceConfig, PortConfig, @@ -117,8 +117,9 @@ async fn run_ptp_session( let event_socket = create_socket(&interface, 319)?; let general_socket = create_socket(&interface, 320)?; - // 6. Add port and run BMCA - let mut port = ptp_instance.add_port(port_config, filter_config, clock, thread_rng()); + // 6. Add port and run BMCA (use StdRng which is Send) + let rng = StdRng::from_entropy(); + let mut port = ptp_instance.add_port(port_config, filter_config, clock, rng); ptp_instance.bmca(&mut [&mut port]); let (mut running_port, initial_actions) = port.end_bmca();