+void io_break(const void *ret)
+{
+ assert(ret);
+ io_loop_return = (void *)ret;
+}
+
+struct io_plan *io_never(struct io_conn *conn, void *unused)
+{
+ return io_always(conn, io_never_called, NULL);
+}
+
+int io_conn_fd(const struct io_conn *conn)
+{
+ return conn->fd.fd;
+}
+
+void io_duplex_prepare(struct io_conn *conn)
+{
+ assert(conn->plan[IO_IN].status == IO_UNSET);
+ assert(conn->plan[IO_OUT].status == IO_UNSET);
+
+ /* We can't sync debug until we've set both: io_wait() and io_always
+ * can't handle it. */
+ conn->debug_saved = conn->debug;
+ io_set_debug(conn, false);
+}
+
+struct io_plan *io_duplex_(struct io_plan *in_plan, struct io_plan *out_plan)
+{
+ struct io_conn *conn;
+
+ /* in_plan must be conn->plan[IO_IN], out_plan must be [IO_OUT] */
+ assert(out_plan == in_plan + 1);
+
+ /* Restore debug. */
+ conn = container_of(in_plan, struct io_conn, plan[IO_IN]);
+ io_set_debug(conn, conn->debug_saved);
+
+ /* Now set the plans again, to invoke sync debug. */
+ io_set_plan(conn, IO_OUT,
+ out_plan->io, out_plan->next, out_plan->next_arg);
+ io_set_plan(conn, IO_IN,
+ in_plan->io, in_plan->next, in_plan->next_arg);
+
+ return out_plan + 1;
+}
+
+struct io_plan *io_halfclose(struct io_conn *conn)