return r;
}
+static void remove_drained_buffers(dlogutil_state_s *state)
+{
+ /* Instead of removing buffers when .read returns 0, we do it
+ * in a separate loop, using their .eof "method". This is because
+ * removing buffers that way would fail if EOF would be triggered
+ * somewhere else and the buffer would never be .read again. */
+
+ for (int i = 0; i < state->fd_count; ++i) {
+ if (!state->enabled[i])
+ continue;
+
+ const struct fd_info *const fdi = state->data_fds[i];
+ if (!fdi->ops->eof(fdi))
+ continue;
+
+ state->enabled[i] = false;
+ epoll_ctl(state->epollfd, EPOLL_CTL_DEL, fdi->fd, NULL);
+ --state->epoll_cnt;
+ }
+}
+
/**
* @brief Handle input
* @details The main loop reading log data
}
}
- /* Instead of removing buffers when ->read returns 0, we do it
- * in a separate loop, using their ->eof "method". This is because
- * removing buffers that way would fail if EOF would be triggered
- * somewhere else and the buffer would never be ->read again. */
- for (int i = 0; i < state->fd_count; ++i) {
- if (state->enabled[i] && state->data_fds[i]->ops->eof(state->data_fds[i])) {
- state->enabled[i] = false;
- epoll_ctl(state->epollfd, EPOLL_CTL_DEL, state->data_fds[i]->fd, NULL);
- --state->epoll_cnt;
- }
- }
+ remove_drained_buffers(state);
}
int r;