summaryrefslogtreecommitdiffstats
path: root/srUtils.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-25 10:45:25 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-25 10:45:25 +0000
commit167abdb5b3fa6900edd6bbdb1cc7d586896a268c (patch)
treebed714a9789bd3f7bd2c86039dfdd4196471b85a /srUtils.c
parent5c686c8adcc473cbdbb14e4b2d736f9123210ee6 (diff)
downloadrsyslog-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-xsrUtils.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/srUtils.c b/srUtils.c
index 590e7eff..4c64ce89 100755
--- a/srUtils.c
+++ b/srUtils.c
@@ -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
*/