+ if (pfd->events)
+ num_waiting--;
+
+ pfd->events = 0;
+ if (conn->plan[IO_IN].status == IO_POLLING)
+ pfd->events |= POLLIN;
+ if (conn->plan[IO_OUT].status == IO_POLLING)
+ pfd->events |= POLLOUT;
+
+ if (pfd->events) {
+ num_waiting++;
+ pfd->fd = conn->fd.fd;
+ } else {
+ pfd->fd = -conn->fd.fd;
+ }
+}
+
+void backend_wake(const void *wait)
+{
+ unsigned int i;
+
+ for (i = 0; i < num_fds; i++) {
+ struct io_conn *c;
+
+ /* Ignore listeners */
+ if (fds[i]->listener)
+ continue;
+
+ c = (void *)fds[i];
+ if (c->plan[IO_IN].status == IO_WAITING
+ && c->plan[IO_IN].arg.u1.const_vp == wait)
+ io_do_wakeup(c, IO_IN);
+
+ if (c->plan[IO_OUT].status == IO_WAITING
+ && c->plan[IO_OUT].arg.u1.const_vp == wait)
+ io_do_wakeup(c, IO_OUT);
+ }
+}
+
+bool add_conn(struct io_conn *c)
+{
+ return add_fd(&c->fd, 0);
+}
+
+static void del_conn(struct io_conn *conn)
+{
+ del_fd(&conn->fd);
+ if (conn->finish) {
+ /* Saved by io_close */
+ errno = conn->plan[IO_IN].arg.u1.s;
+ conn->finish(conn, conn->finish_arg);