refactor: update statime Port API method calls for timer and message handling

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

View file

@ -102,7 +102,7 @@ async fn run_ptp_session(
// 5. Create network handles
fn create_socket(
interface: &str,
_interface: &str,
port: u16,
) -> Result<UdpSocket, Box<dyn std::error::Error + Send + Sync>> {
let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?;
@ -159,22 +159,20 @@ async fn run_ptp_session(
return Ok(());
}
let timer_instant = running_port
.get_next_timer_instant()
.map(tokio::time::Instant::from_std)
.unwrap_or_else(|| tokio::time::Instant::now() + Duration::from_secs(1));
actions = Vec::new();
tokio::select! {
_ = tokio::time::sleep_until(timer_instant) => {
actions.extend(running_port.handle_timer());
_ = tokio::time::sleep(Duration::from_millis(100)) => {
// Handle periodic timer events
actions.extend(running_port.handle_sync_timer());
actions.extend(running_port.handle_announce_timer());
actions.extend(running_port.handle_delay_request_timer());
}
Ok((len, source_address)) = event_socket.recv_from(&mut event_buf) => {
actions.extend(running_port.handle_message(&event_buf[..len], source_address));
actions.extend(running_port.handle_event_receive(&event_buf[..len], source_address));
}
Ok((len, source_address)) = general_socket.recv_from(&mut general_buf) => {
actions.extend(running_port.handle_message(&general_buf[..len], source_address));
actions.extend(running_port.handle_general_receive(&general_buf[..len], source_address));
}
}