summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-05-06 11:02:16 -0700
committerGarrett D'Amore <garrett@damore.org>2018-05-06 15:11:48 -0700
commit7ecb0e4a74bbb3d49ebe37a14b2534a242cb930a (patch)
tree53e514758b9312d183d33cdd829a684a16437fc2
parentafd555af4fba0acbf16c174dd9dece24181a1a38 (diff)
downloadnng-7ecb0e4a74bbb3d49ebe37a14b2534a242cb930a.tar.gz
nng-7ecb0e4a74bbb3d49ebe37a14b2534a242cb930a.tar.bz2
nng-7ecb0e4a74bbb3d49ebe37a14b2534a242cb930a.zip
fixes #401 timer overflow error in convey
-rw-r--r--tests/convey.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/convey.c b/tests/convey.c
index 2dd4c323..c676ecaa 100644
--- a/tests/convey.c
+++ b/tests/convey.c
@@ -509,15 +509,17 @@ convey_start_timer(struct convey_timer *pc)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- pc->timer_base = (uint64_t) ts.tv_sec * 1000000000;
- pc->timer_base += (uint64_t) ts.tv_nsec;
+ pc->timer_base = ts.tv_sec;
+ pc->timer_base *= 1000000000;
+ pc->timer_base += ts.tv_nsec;
pc->timer_rate = 1000000000;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
- pc->timer_base = (uint64_t) tv.tv_sec * 1000000;
- pc->timer_base += (uint64_t) tv.tv_usec;
+ pc->timer_base = tv.tv_sec;
+ pc->timer_base *= 1000000;
+ pc->timer_base += tv.tv_usec;
pc->timer_rate = 1000000;
#endif
pc->timer_running = 1;
@@ -539,7 +541,8 @@ convey_stop_timer(struct convey_timer *pc)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- ns = (ts.tv_sec * 1000000000);
+ ns = ts.tv_sec;
+ ns *= 1000000000;
ns += (uint64_t) ts.tv_nsec;
pc->timer_count += (ns - pc->timer_base);
#else
@@ -547,7 +550,8 @@ convey_stop_timer(struct convey_timer *pc)
struct timeval tv;
gettimeofday(&tv, NULL);
- us = (tv.tv_sec * 1000000);
+ us = tv.tv_sec;
+ us *= 1000000;
us += tv.tv_usec;
pc->timer_count += (us - pc->timer_base);
#endif