refactor: resolve borrowing issues in PTP module

Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-07-10 18:24:21 +01:00
parent 6454d5f5ce
commit 9aa5d00ee1

View file

@ -80,7 +80,7 @@ async fn run_ptp_session(
TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator); TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
// 2. Create PtpInstance // 2. Create PtpInstance
let mut ptp_instance = PtpInstance::<BasicFilter>::new(instance_config, time_properties_ds); let ptp_instance = PtpInstance::<BasicFilter>::new(instance_config, time_properties_ds);
// 3. Create PortConfig // 3. Create PortConfig
let port_config = PortConfig { let port_config = PortConfig {
@ -164,19 +164,30 @@ async fn run_ptp_session(
tokio::select! { tokio::select! {
_ = tokio::time::sleep(Duration::from_millis(100)) => { _ = tokio::time::sleep(Duration::from_millis(100)) => {
// Handle periodic timer events one at a time to avoid multiple mutable borrows // Handle periodic timer events one at a time to avoid multiple mutable borrows
actions.extend(running_port.handle_sync_timer()); let sync_actions: Vec<_> = running_port.handle_sync_timer().collect();
actions.extend(running_port.handle_announce_timer(&mut NoForwardedTLVs)); actions.extend(sync_actions);
actions.extend(running_port.handle_delay_request_timer());
let announce_actions: Vec<_> = running_port.handle_announce_timer(&mut NoForwardedTLVs).collect();
actions.extend(announce_actions);
let delay_actions: Vec<_> = running_port.handle_delay_request_timer().collect();
actions.extend(delay_actions);
} }
Ok((len, _source_address)) = event_socket.recv_from(&mut event_buf) => { Ok((len, _source_address)) = event_socket.recv_from(&mut event_buf) => {
let receive_time = Time::from_nanos(std::time::SystemTime::now() let receive_time = Time::from_nanos(std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH) .duration_since(std::time::UNIX_EPOCH)
.unwrap() .unwrap()
.as_nanos() as u64); .as_nanos() as u64);
actions.extend(running_port.handle_event_receive(&event_buf[..len], receive_time)); // Copy the data to avoid borrowing conflicts
let data = event_buf[..len].to_vec();
let event_actions: Vec<_> = running_port.handle_event_receive(&data, receive_time).collect();
actions.extend(event_actions);
} }
Ok((len, _source_address)) = general_socket.recv_from(&mut general_buf) => { Ok((len, _source_address)) = general_socket.recv_from(&mut general_buf) => {
actions.extend(running_port.handle_general_receive(&general_buf[..len])); // Copy the data to avoid borrowing conflicts
let data = general_buf[..len].to_vec();
let general_actions: Vec<_> = running_port.handle_general_receive(&data).collect();
actions.extend(general_actions);
} }
} }