Skip to content

Commit

Permalink
affile/poll-file-changes: indicate immediate readability if we are no…
Browse files Browse the repository at this point in the history
…t at EOF

Previously this case was handled using the complex "immediate_check"
logic, which I am about to get rid of.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Dec 9, 2024
1 parent ed67403 commit 9590d34
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions modules/affile/poll-file-changes.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,18 @@ poll_file_changes_stop_watches(PollEvents *s)
}

static void
poll_file_changes_rearm_timer(PollFileChanges *self)
poll_file_changes_rearm_timer(PollFileChanges *self, glong delay)
{
iv_validate_now();
self->follow_timer.expires = iv_now;
timespec_add_msec(&self->follow_timer.expires, self->follow_freq);
timespec_add_msec(&self->follow_timer.expires, delay);
iv_timer_register(&self->follow_timer);
}

static gboolean
poll_file_changes_check_eof(PollFileChanges *self)
{
gint fd = self->fd;
if (fd < 0)
return FALSE;

off_t pos = lseek(fd, 0, SEEK_CUR);
if (pos == (off_t) -1)
Expand All @@ -202,22 +200,32 @@ void
poll_file_changes_update_watches(PollEvents *s, GIOCondition cond)
{
PollFileChanges *self = (PollFileChanges *) s;
gboolean check_again = TRUE;

/* we can only provide input events */
g_assert((cond & ~G_IO_IN) == 0);

poll_file_changes_stop_watches(s);

if (self->fd < 0)
{
/* file does not exist yet, go back checking after follow_freq */
poll_file_changes_rearm_timer(self, self->follow_freq);
return;
}

if (poll_file_changes_check_eof(self))
{
msg_trace("End of file, following file",
evt_tag_str("follow_filename", self->follow_filename));
check_again = poll_file_changes_on_eof(self);
if (poll_file_changes_on_eof(self))
poll_file_changes_rearm_timer(self, self->follow_freq);
}
else
{
msg_trace("File exists and contains data",
evt_tag_str("follow_filename", self->follow_filename));
poll_file_changes_rearm_timer(self, 0);
}

if (check_again)
poll_file_changes_rearm_timer(self);
}

void
Expand Down

0 comments on commit 9590d34

Please sign in to comment.