mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
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:
parent
ac553146a1
commit
b2aa3c3d07
1 changed files with 8 additions and 10 deletions
18
src/ptp.rs
18
src/ptp.rs
|
|
@ -102,7 +102,7 @@ async fn run_ptp_session(
|
||||||
|
|
||||||
// 5. Create network handles
|
// 5. Create network handles
|
||||||
fn create_socket(
|
fn create_socket(
|
||||||
interface: &str,
|
_interface: &str,
|
||||||
port: u16,
|
port: u16,
|
||||||
) -> Result<UdpSocket, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<UdpSocket, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?;
|
let socket = Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?;
|
||||||
|
|
@ -159,22 +159,20 @@ async fn run_ptp_session(
|
||||||
return Ok(());
|
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();
|
actions = Vec::new();
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = tokio::time::sleep_until(timer_instant) => {
|
_ = tokio::time::sleep(Duration::from_millis(100)) => {
|
||||||
actions.extend(running_port.handle_timer());
|
// 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) => {
|
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) => {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue