+ if (num_exclusive && !*exclusive(plan))
+ continue;
+ /* Remove first: it might re-add */
+ if (i != num_always-1)
+ always[i] = always[num_always-1];
+ num_always--;
+ io_do_always(plan);
+ return true;
+ }
+
+ return false;
+}
+
+bool backend_set_exclusive(struct io_plan *plan, bool excl)
+{
+ bool *excl_ptr = exclusive(plan);
+
+ if (excl != *excl_ptr) {
+ *excl_ptr = excl;
+ if (!excl)
+ num_exclusive--;
+ else
+ num_exclusive++;
+ }
+
+ return num_exclusive != 0;
+}
+
+/* FIXME: We could do this once at set_exclusive time, and catch everywhere
+ * else that we manipulate events. */
+static void exclude_pollfds(void)
+{
+ if (num_exclusive == 0)
+ return;
+
+ for (size_t i = 0; i < num_fds; i++) {
+ struct pollfd *pfd = &pollfds[fds[i]->backend_info];
+
+ if (!fds[i]->exclusive[IO_IN])
+ pfd->events &= ~POLLIN;
+ if (!fds[i]->exclusive[IO_OUT])
+ pfd->events &= ~POLLOUT;
+
+ /* If we're not listening, we don't want error events
+ * either. */
+ if (!pfd->events)
+ pfd->fd = -fds[i]->fd - 1;
+ }
+}
+
+static void restore_pollfds(void)
+{
+ if (num_exclusive == 0)
+ return;
+
+ for (size_t i = 0; i < num_fds; i++) {
+ struct pollfd *pfd = &pollfds[fds[i]->backend_info];
+
+ if (fds[i]->listener) {
+ pfd->events = POLLIN;
+ pfd->fd = fds[i]->fd;
+ } else {
+ struct io_conn *conn = (void *)fds[i];
+ setup_pfd(conn, pfd);
+ }