pollfds = tal_free(pollfds);
fds = NULL;
max_fds = 0;
+ if (num_always == 0) {
+ always = tal_free(always);
+ max_always = 0;
+ }
}
num_fds--;
fd->backend_info = -1;
static int find_always(const struct io_plan *plan)
{
- for (size_t i = 0; i < num_always; i++)
+ size_t i = 0;
+
+ for (i = 0; i < num_always; i++)
if (always[i] == plan)
return i;
return -1;
/* Only free if no fds left either. */
if (num_always == 0 && max_fds == 0) {
- tal_free(always);
+ always = tal_free(always);
max_always = 0;
}
}
/* For simplicity, we do one always at a time */
static bool handle_always(void)
{
+ int i;
+
/* Backwards is simple easier to remove entries */
- for (int i = num_always - 1; i >= 0; i--) {
+ for (i = num_always - 1; i >= 0; i--) {
struct io_plan *plan = always[i];
if (num_exclusive && !*exclusive(plan))
* else that we manipulate events. */
static void exclude_pollfds(void)
{
+ size_t i;
+
if (num_exclusive == 0)
return;
- for (size_t i = 0; i < num_fds; i++) {
+ for (i = 0; i < num_fds; i++) {
struct pollfd *pfd = &pollfds[fds[i]->backend_info];
if (!fds[i]->exclusive[IO_IN])
static void restore_pollfds(void)
{
+ size_t i;
+
if (num_exclusive == 0)
return;
- for (size_t i = 0; i < num_fds; i++) {
+ for (i = 0; i < num_fds; i++) {
struct pollfd *pfd = &pollfds[fds[i]->backend_info];
if (fds[i]->listener) {
return ret;
}
+
+const void *io_have_fd(int fd, bool *listener)
+{
+ for (size_t i = 0; i < num_fds; i++) {
+ if (fds[i]->fd != fd)
+ continue;
+ if (listener)
+ *listener = fds[i]->listener;
+ return fds[i];
+ }
+ return NULL;
+}