ntp: check for zero timestamp in initial TX timeout

Calculate the delay since the previous transmission only if the
TX timestamp is actually set. This removes an unnecessary delay when
starting at the Unix epoch in 1970 (e.g. in a test).
This commit is contained in:
Miroslav Lichvar 2021-12-01 09:11:09 +01:00
parent 53353529cf
commit 6a79771898

View file

@ -493,11 +493,16 @@ start_initial_timeout(NCR_Instance inst)
/* In case the offline period was too short, adjust the delay to keep /* In case the offline period was too short, adjust the delay to keep
the interval between packets at least as long as the current polling the interval between packets at least as long as the current polling
interval */ interval */
SCH_GetLastEventTime(&now, NULL, NULL); if (!UTI_IsZeroTimespec(&inst->local_tx.ts)) {
last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts); SCH_GetLastEventTime(&now, NULL, NULL);
if (last_tx < 0.0) last_tx = UTI_DiffTimespecsToDouble(&now, &inst->local_tx.ts);
last_tx = 0.0; if (last_tx < 0.0)
delay = get_transmit_delay(inst, 0, 0.0) - last_tx; last_tx = 0.0;
delay = get_transmit_delay(inst, 0, 0.0) - last_tx;
} else {
delay = 0.0;
}
if (delay < INITIAL_DELAY) if (delay < INITIAL_DELAY)
delay = INITIAL_DELAY; delay = INITIAL_DELAY;