aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);