- set_current(NULL);
-
- /* If it closed, close duplex. */
- if (!conn->plan.next && conn->duplex) {
- set_current(conn->duplex);
- conn->duplex->plan = io_close();
- backend_plan_changed(conn->duplex);
- set_current(NULL);
+}
+
+void io_ready(struct io_conn *conn, int pollflags)
+{
+ if (pollflags & POLLIN)
+ if (!do_plan(conn, &conn->plan[IO_IN], false))
+ return;
+
+ if (pollflags & POLLOUT)
+ /* If we're writing to a closed pipe, we need to wait for
+ * read to fail if we're duplex: we want to drain it! */
+ do_plan(conn, &conn->plan[IO_OUT],
+ conn->plan[IO_IN].status == IO_POLLING_NOTSTARTED
+ || conn->plan[IO_IN].status == IO_POLLING_STARTED);
+}
+
+void io_do_always(struct io_conn *conn)
+{
+ /* There's a corner case where the in next_plan wakes up the
+ * out, placing it in IO_ALWAYS and we end up processing it immediately,
+ * only to leave it in the always list.
+ *
+ * Yet we can't just process one, in case they are both supposed
+ * to be done, so grab state beforehand.
+ */
+ bool always_out = (conn->plan[IO_OUT].status == IO_ALWAYS);
+
+ if (conn->plan[IO_IN].status == IO_ALWAYS)
+ if (!next_plan(conn, &conn->plan[IO_IN]))
+ return;
+
+ if (always_out) {
+ /* You can't *unalways* a conn (except by freeing, in which
+ * case next_plan() returned false */
+ assert(conn->plan[IO_OUT].status == IO_ALWAYS);
+ next_plan(conn, &conn->plan[IO_OUT]);