+
+ rio->read_prev_avail = 0;
+ return rec_io_process_read_buf(rio);
+}
+
+static void
+rec_io_recalc_read(struct main_rec_io *rio)
+{
+ uns flow = !rio->write_throttle_read || rio->write_watermark < rio->write_throttle_read;
+ uns run = rio->read_started && flow;
+ DBG("RIO: Recalc read (flow=%u, start=%u) -> %u", flow, rio->read_started, run);
+ if (run != rio->read_running)
+ {
+ if (run)
+ {
+ /*
+ * Since we need to rescan the read buffer for leftover records and we
+ * can be deep in the call stack at this moment, we better defer most
+ * of the work to a main_hook, which will be called in the next iteration
+ * of the main loop.
+ */
+ if (!hook_is_active(&rio->start_read_hook))
+ {
+ DBG("RIO: Scheduling start of reading");
+ hook_add(&rio->start_read_hook);
+ }
+ }
+ else
+ {
+ if (hook_is_active(&rio->start_read_hook))
+ {
+ DBG("RIO: Descheduling start of reading");
+ hook_del(&rio->start_read_hook);
+ }
+ rio->file.read_handler = NULL;
+ file_chg(&rio->file);
+ DBG("RIO: Reading stopped");
+ rio->read_running = 0;
+ }
+ }
+}
+
+void
+rec_io_start_read(struct main_rec_io *rio)
+{
+ ASSERT(rec_io_is_active(rio));
+ rio->read_started = 1;
+ rec_io_recalc_read(rio);