+ /* TODO: Set timeout on fifo_read_all based on diff of last time of
+ * fifo_read_all and desired time of next TTL check.
+ */
+ /* TODO: How long to wait on IO? Max TTL? */
+ reading = fifo_read_all(cfg, buf);
+ debug("reading: %d\n", reading);
+ if (cfg->output_to_x_root_window) {
+ if (XStoreName(display, DefaultRootWindow(display), buf) < 0)
+ fatal("XStoreName failed.\n");
+ XFlush(display);
+ } else {
+ puts(buf);
+ fflush(stdout);
+ }
+ clock_gettime(CLOCK_MONOTONIC, &t1); // FIXME: check errors
+ timespecsub(&t1, &t0, &td);
+ debug("td {tv_sec = %ld, tv_nsec = %ld}\n", td.tv_sec, td.tv_nsec);
+ /*
+ * Skip sleep when we aren't done reading,
+ * to avoid filling-up the pipe during sleep.
+ */
+ if (!reading && timespeccmp(&td, &ti, <)) {
+ /* Pushback on data producers by refusing to read the
+ * pipe more frequently than the interval.
+ */
+ /* FIXME: Client is never blocked after initial open. */
+ timespecsub(&ti, &td, &tc);
+ debug("snooze YES\n");
+ snooze(&tc);
+ } else {
+ debug("snooze NO\n");
+ }