"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in
news:OLqbQdTBIHA.1208@TK2MSFTNGP03.phx.gbl:
You have been computing the time between packets and sleeping that
long. This is wrong, because errors build up forever. Instead,
calculate, based on the time of the first packet and the packet
number, when the next packet should be sent. CreateWaitableTimer
allows you to wait for a specific time instead of a specific delay.
If Windows slept too long in one instance, the next sleep you receive
will be shorter, and the average rate will be exactly correct.
Consider also that you might sleep more than one interval, as some other
high priority task takes the CPU for one or more slices. Do you send two
packets? Or drop the packet that would have been sent while the other task
was hogging the system? That's very application-dependent, of course. (In
USB and Firewire terminology, that's the difference between "bulk" and
"isochronous" transmissions.)
packets... up to a point, when I drop the earliest packets and send only the
most recent few packets to get the receiver buffer half-full again.