Skip to content

Commit

Permalink
watcher: Avoid queueing multiple watcher callbacks at the same time
Browse files Browse the repository at this point in the history
While we don't add FDs with an active callback to the watched FDSET, we still
can get notifications for callbacks active due the asynchronous processing
of the same.

To avoid queue multiple callbacks, we check for queued callbacks before
activating new ones.
  • Loading branch information
martinwilli committed May 7, 2014
1 parent 874e212 commit d16d5a2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libstrongswan/processing/watcher.c
Expand Up @@ -238,6 +238,7 @@ static job_requeue_t watch(private_watcher_t *this)
entry_t *entry;
fd_set rd, wr, ex;
int maxfd = 0, res;
bool rebuild = FALSE;

FD_ZERO(&rd);
FD_ZERO(&wr);
Expand Down Expand Up @@ -282,7 +283,7 @@ static job_requeue_t watch(private_watcher_t *this)
enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex);

while (TRUE)
while (!rebuild)
{
char buf[1];
bool old;
Expand All @@ -308,6 +309,11 @@ static job_requeue_t watch(private_watcher_t *this)
enumerator = this->fds->create_enumerator(this->fds);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->in_callback)
{
rebuild = TRUE;
break;
}
if (FD_ISSET(entry->fd, &rd) && (entry->events & WATCHER_READ))
{
DBG2(DBG_JOB, "watched FD %d ready to read", entry->fd);
Expand Down Expand Up @@ -347,6 +353,7 @@ static job_requeue_t watch(private_watcher_t *this)
return JOB_REQUEUE_DIRECT;
}
}
return JOB_REQUEUE_DIRECT;
}

METHOD(watcher_t, add, void,
Expand Down

0 comments on commit d16d5a2

Please sign in to comment.