+ /* First, check if it's time to do the cache flush. */
+ gettimeofday (&now, NULL);
+ if ((now.tv_sec > next_flush.tv_sec)
+ || ((now.tv_sec == next_flush.tv_sec)
+ && ((1000 * now.tv_usec) > next_flush.tv_nsec)))
+ {
+ time_t time_now;
+
+ /* Pass the current time as user data so that we don't need to call
+ * `time' for each node. */
+ time_now = time (NULL);
+
+ g_tree_foreach (cache_tree, tree_callback_flush, (gpointer) &time_now);
+
+ /* Determine the time of the next cache flush. */
+ while (next_flush.tv_sec < now.tv_sec)
+ next_flush.tv_sec += config_flush_interval;
+ }
+
+ /* Now, check if there's something to store away. If not, wait until
+ * something comes in or it's time to do the cache flush. */