summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2007-08-11 22:40:38 +0800
committerDavid Woodhouse <dwmw2@infradead.org>2007-08-11 22:40:38 +0800
commit34a3278c85e883e3279b14acd57b02610c1039e3 (patch)
tree9299fe9437c59c91848cc038ccdabfc8e55c3e8f
parent96daeacf50668871a5fc4f7dc2cc9237f7035f03 (diff)
Fix timing calculations for serve_image
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
-rw-r--r--serve_image.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/serve_image.c b/serve_image.c
index d2e3390..dc434f0 100644
--- a/serve_image.c
+++ b/serve_image.c
@@ -112,6 +112,7 @@ int main(int argc, char **argv)
nr_blocks = st.st_size / erasesize;
printf("Checking CRC....");
+ fflush(stdout);
pktbuf.hdr.resend = 0;
pktbuf.hdr.totcrc = htonl(crc32(-1, image, st.st_size));
@@ -196,30 +197,18 @@ int main(int argc, char **argv)
now.tv_usec < nextpkt.tv_usec));
nextpkt.tv_usec = now.tv_usec + pkt_delay;
- if (nextpkt.tv_usec > 1000000) {
+ if (nextpkt.tv_usec >= 1000000) {
nextpkt.tv_sec += nextpkt.tv_usec / 1000000;
nextpkt.tv_usec %= 1000000;
}
-#if 0
- /* Delay, if we are so far ahead of ourselves that we have at
- least one tick to wait. */
-
- gettimeofday(&now, NULL);
- nextpkt.tv_usec = now.tv_usec +
- /* Add to pkt_delay if necessary */
- delay_accum += pkt_delay;
- delay_accum -= (now.tv_usec - blkthen.tv_usec);
- delay_accum -= 1000000 * (now.tv_sec - blkthen.tv_sec);
- if (delay_accum < 0)
- delay_accum = 0;
- blkthen = now;
-
- if (delay_accum >= usec_per_tick) {
- usleep(delay_accum);
- delay_accum = 0;
- } printf("delay_accum %ld\n", delay_accum);
-#endif
+ /* If the time for the next packet has already
+ passed, then we've lost time. Adjust our expected
+ timings accordingly. */
+ if (now.tv_usec > (now.tv_usec +
+ 1000000 * (nextpkt.tv_sec - now.tv_sec)))
+ nextpkt = now;
+
}
}
munmap(image, st.st_size);