* fixed some tv_cmp_ms() computations. Strictly speaking, there was
a very short window of 1 microsecond every millisecond during which
two events were not considered as 1 ms apart from each other.
diff --git a/haproxy.c b/haproxy.c
index 4cfa8ce..0da06a9 100644
--- a/haproxy.c
+++ b/haproxy.c
@@ -1373,18 +1373,18 @@
*/
static inline int tv_cmp_ms(struct timeval *tv1, struct timeval *tv2) {
if (tv1->tv_sec == tv2->tv_sec) {
- if (tv2->tv_usec > tv1->tv_usec + 1000)
+ if (tv2->tv_usec >= tv1->tv_usec + 1000)
return -1;
- else if (tv1->tv_usec > tv2->tv_usec + 1000)
+ else if (tv1->tv_usec >= tv2->tv_usec + 1000)
return 1;
else
return 0;
}
else if ((tv2->tv_sec > tv1->tv_sec + 1) ||
- ((tv2->tv_sec == tv1->tv_sec + 1) && (tv2->tv_usec + 1000000 > tv1->tv_usec + 1000)))
+ ((tv2->tv_sec == tv1->tv_sec + 1) && (tv2->tv_usec + 1000000 >= tv1->tv_usec + 1000)))
return -1;
else if ((tv1->tv_sec > tv2->tv_sec + 1) ||
- ((tv1->tv_sec == tv2->tv_sec + 1) && (tv1->tv_usec + 1000000 > tv2->tv_usec + 1000)))
+ ((tv1->tv_sec == tv2->tv_sec + 1) && (tv1->tv_usec + 1000000 >= tv2->tv_usec + 1000)))
return 1;
else
return 0;
@@ -1468,18 +1468,18 @@
return -1; /* tv2 later than tv1 */
if (tv1->tv_sec == tv2->tv_sec) {
- if (tv1->tv_usec > tv2->tv_usec + 1000)
+ if (tv1->tv_usec >= tv2->tv_usec + 1000)
return 1;
- else if (tv2->tv_usec > tv1->tv_usec + 1000)
+ else if (tv2->tv_usec >= tv1->tv_usec + 1000)
return -1;
else
return 0;
}
else if ((tv1->tv_sec > tv2->tv_sec + 1) ||
- ((tv1->tv_sec == tv2->tv_sec + 1) && (tv1->tv_usec + 1000000 > tv2->tv_usec + 1000)))
+ ((tv1->tv_sec == tv2->tv_sec + 1) && (tv1->tv_usec + 1000000 >= tv2->tv_usec + 1000)))
return 1;
else if ((tv2->tv_sec > tv1->tv_sec + 1) ||
- ((tv2->tv_sec == tv1->tv_sec + 1) && (tv2->tv_usec + 1000000 > tv1->tv_usec + 1000)))
+ ((tv2->tv_sec == tv1->tv_sec + 1) && (tv2->tv_usec + 1000000 >= tv1->tv_usec + 1000)))
return -1;
else
return 0;