libdlogutil: split off buffer removal 28/229528/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 31 Mar 2020 17:35:34 +0000 (19:35 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Thu, 2 Apr 2020 14:06:31 +0000 (16:06 +0200)
Change-Id: Ic4cefeb97d836eaf41eb355c1907f963018e5bfb

src/libdlogutil/logretrieve.c

index 493c390..7a89395 100644 (file)
@@ -265,6 +265,27 @@ static bool handle_flush(dlogutil_state_s *state, dlogutil_entry_s **out)
        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
@@ -325,17 +346,7 @@ int do_print_once(dlogutil_state_s *state, int timeout, dlogutil_entry_s **out)
                        }
                }
 
-               /* 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;