diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-25 10:45:25 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-01-25 10:45:25 +0000 |
commit | 167abdb5b3fa6900edd6bbdb1cc7d586896a268c (patch) | |
tree | bed714a9789bd3f7bd2c86039dfdd4196471b85a /srUtils.c | |
parent | 5c686c8adcc473cbdbb14e4b2d736f9123210ee6 (diff) | |
download | rsyslog-167abdb5b3fa6900edd6bbdb1cc7d586896a268c.tar.gz rsyslog-167abdb5b3fa6900edd6bbdb1cc7d586896a268c.tar.xz rsyslog-167abdb5b3fa6900edd6bbdb1cc7d586896a268c.zip |
restructured queue shutdown so that the queue timeout is properly applied
before terminatiing the queue
Diffstat (limited to 'srUtils.c')
-rwxr-xr-x | srUtils.c | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -316,7 +316,7 @@ int getNumberDigits(long lNum) * rgerhards, 2008-01-14 */ rsRetVal -timeoutComp(struct timespec *pt, int iTimeout) +timeoutComp(struct timespec *pt, long iTimeout) { assert(pt != NULL); /* compute timeout */ @@ -331,6 +331,38 @@ timeoutComp(struct timespec *pt, int iTimeout) } +/* This function is kind of the reverse of timeoutComp() - it takes an absolute + * timeout value and computes how far this is in the future. If the value is already + * in the past, 0 is returned. The return value is in ms. + * rgerhards, 2008-01-25 + */ +long +timeoutVal(struct timespec *pt) +{ + struct timespec t; + long iTimeout; + + assert(pt != NULL); + /* compute timeout */ + clock_gettime(CLOCK_REALTIME, &t); + if(pt->tv_sec < t.tv_sec) { + iTimeout = 0; /* in the past! */ + } else if(pt->tv_sec == t.tv_sec) { + if(pt->tv_nsec < t.tv_nsec) { + iTimeout = 0; /* in the past! */ + } else { + iTimeout = (pt->tv_nsec - t.tv_nsec) / 1000; + } + } else { + iTimeout = pt->tv_sec - t.tv_nsec; + iTimeout += 1000 - (pt->tv_nsec / 1000); + iTimeout += t.tv_nsec / 1000; + } + + return iTimeout; +} + + /* cancellation cleanup handler - frees provided mutex * rgerhards, 2008-01-14 */ |