+ io_loop_return = do_io_loop(&ready);
+
+ if (ready) {
+ set_current(ready);
+ if (!ready->plan.next) {
+ /* Call finish function immediately. */
+ if (ready->finish) {
+ errno = ready->plan.u1.s;
+ ready->finish(ready, ready->finish_arg);
+ ready->finish = NULL;
+ }
+ backend_del_conn(ready);
+ } else {
+ /* Calls back in itself, via io_debug_io(). */
+ if (ready->plan.io(ready->fd.fd, &ready->plan) != 2)
+ abort();
+ }
+ set_current(NULL);
+ }
+
+ /* Return a do-nothing plan, so backend_plan_changed in
+ * io_ready doesn't do anything (it's already been called). */
+ return io_idle_();
+}
+
+int io_debug_io(int ret)
+{
+ /* Cache it for debugging; current changes. */
+ struct io_conn *conn = current;
+ int saved_errno = errno;
+
+ if (!doing_debug_on(conn))
+ return ret;
+
+ /* These will all go linearly through the io_debug() path above. */
+ switch (ret) {
+ case -1:
+ /* This will call io_debug above. */
+ errno = saved_errno;
+ io_close();
+ break;
+ case 0: /* Keep going with plan. */
+ io_debug(conn->plan);
+ break;
+ case 1: /* Done: get next plan. */
+ if (timeout_active(conn))
+ backend_del_timeout(conn);
+ /* In case they call io_duplex, clear our poll flags so
+ * both sides don't seem to be both doing read or write
+ * (See assert(!mask || pfd->events != mask) in poll.c) */
+ conn->plan.pollflag = 0;
+ conn->plan.next(conn, conn->plan.next_arg);
+ break;
+ default:
+ abort();
+ }
+
+ /* Normally-invalid value, used for sanity check. */
+ return 2;