mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
refactor: simplify PTP event handling to resolve borrow checker conflicts
Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
parent
9aa5d00ee1
commit
85cd0cc7db
1 changed files with 7 additions and 18 deletions
25
src/ptp.rs
25
src/ptp.rs
|
|
@ -163,35 +163,24 @@ async fn run_ptp_session(
|
||||||
// Handle events and collect new actions
|
// Handle events and collect new actions
|
||||||
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 timer events sequentially to avoid multiple mutable borrows
|
||||||
let sync_actions: Vec<_> = running_port.handle_sync_timer().collect();
|
actions.extend(running_port.handle_sync_timer());
|
||||||
actions.extend(sync_actions);
|
actions.extend(running_port.handle_announce_timer(&mut NoForwardedTLVs));
|
||||||
|
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);
|
||||||
// Copy the data to avoid borrowing conflicts
|
actions.extend(running_port.handle_event_receive(&event_buf[..len], receive_time));
|
||||||
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) => {
|
||||||
// Copy the data to avoid borrowing conflicts
|
actions.extend(running_port.handle_general_receive(&general_buf[..len]));
|
||||||
let data = general_buf[..len].to_vec();
|
|
||||||
let general_actions: Vec<_> = running_port.handle_general_receive(&data).collect();
|
|
||||||
actions.extend(general_actions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update shared state periodically
|
// Update shared state periodically (after all mutable operations are done)
|
||||||
if last_state_update.elapsed() > Duration::from_millis(500) {
|
if last_state_update.elapsed() > Duration::from_millis(500) {
|
||||||
let port_ds = running_port.port_ds();
|
let port_ds = running_port.port_ds();
|
||||||
let mut st = state.lock().unwrap();
|
let mut st = state.lock().unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue