и посылать пакет нужного размера. Изначально было:
```
loop {
let pkt = get_packet(seq);
let req = TestRequest {
seq: pkt.seq as u32,
timestamp: Utc::now(),
err_estimate: 0,
pad_to: pkt.size - udp_overhead,
};
req.write_bytes(&mut buf)?;
//
out_octets += socket.send_to(&buf, addr).await? + udp_overhead;
pkt_sent += 1;
// Reset buffer pointer
buf.clear();
//
seq += 1;
if seq == n_packets {
break;
}
//
if pkt.next_ns == 0 {
continue; // Flood mode
}
// Wait for next packet time
if err_ns < pkt.next_ns {
let delta_ns = pkt.next_ns - err_ns;
tokio::time::sleep_until(now + Duration::from_nanos(delta_ns)).await;
// As for version 1.2, Tokio timer has precision about 1ms,
// It will lead to significant drift ever on 50pps rates.
// so we need to add error correction to be more precise.
let prev_now = now;
now = tokio::time::Instant::now();
let real_delta_ns = (now - prev_now).as_nanos() as u64;
err_ns = real_delta_ns - delta_ns;
} else {
err_ns -= pkt.next_ns;
}
}
```
tokio::time::interval тоже плывёт?
Обсуждают сегодня