diff --git a/nwatch.c b/nwatch.c index bf57d95d..59e6d0eb 100644 --- a/nwatch.c +++ b/nwatch.c @@ -403,11 +403,23 @@ int NetWatchTask (void* pData) } NetWatchTimerRemQue(self, pNew); iStatus = pNew->func(pNew->cntx, 0); + /* + * If this is a recurrent timer and the function + * indicates to keep it going, put it back in + */ if (pNew->tick && iStatus == 1) { - pNew->tv.tv_usec += 1000 * pNew->tick; - if (pNew->tv.tv_usec > 1000000) { - pNew->tv.tv_sec += pNew->tv.tv_usec / 1000000; - pNew->tv.tv_usec %= 1000000; + /* + * While the expiration time is in the past, increment + */ + gettimeofday(&tv, NULL); + while (tv.tv_sec > pNew->tv.tv_sec || + (tv.tv_sec == pNew->tv.tv_sec && + tv.tv_usec > pNew->tv.tv_usec)) { + pNew->tv.tv_usec += 1000 * pNew->tick; + if (pNew->tv.tv_usec > 1000000) { + pNew->tv.tv_sec += pNew->tv.tv_usec / 1000000; + pNew->tv.tv_usec %= 1000000; + } } NetWatchTimerInsQue(self, pNew); }