From abf33c87f944ff3f68b6b108e5e0d6560e55cd5e Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 29 May 2012 19:54:36 +0200 Subject: [PATCH] fixed bug #3526909 (Wrong unit conversion) pointed out by jsucaet Applied patch provided by jsucaet. --- coap_time.h | 2 +- examples/client.c | 6 +++--- examples/etsi_iot_01.c | 2 +- examples/rd.c | 2 +- examples/server.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coap_time.h b/coap_time.h index be8fbbde..62331dbc 100644 --- a/coap_time.h +++ b/coap_time.h @@ -77,7 +77,7 @@ coap_ticks_impl(coap_tick_t *t) { struct timeval tv; gettimeofday(&tv, NULL); *t = (tv.tv_sec - clock_offset) * COAP_TICKS_PER_SECOND - + (tv.tv_usec >> 10) % COAP_TICKS_PER_SECOND; + + (tv.tv_usec * COAP_TICKS_PER_SECOND / 1000000); #else #error "clock not implemented" #endif diff --git a/examples/client.c b/examples/client.c index 3e4dd10d..e60e12f3 100644 --- a/examples/client.c +++ b/examples/client.c @@ -1095,15 +1095,15 @@ main(int argc, char **argv) { if (nextpdu && nextpdu->t < min(obs_wait ? obs_wait : max_wait, max_wait)) { /* set timeout if there is a pdu to send */ - tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) << 10; + tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; } else { /* check if obs_wait fires before max_wait */ if (obs_wait && obs_wait < max_wait) { - tv.tv_usec = ((obs_wait - now) % COAP_TICKS_PER_SECOND) << 10;; + tv.tv_usec = ((obs_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (obs_wait - now) / COAP_TICKS_PER_SECOND; } else { - tv.tv_usec = ((max_wait - now) % COAP_TICKS_PER_SECOND) << 10;; + tv.tv_usec = ((max_wait - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (max_wait - now) / COAP_TICKS_PER_SECOND; } } diff --git a/examples/etsi_iot_01.c b/examples/etsi_iot_01.c index 5f7fe2a0..1269625a 100644 --- a/examples/etsi_iot_01.c +++ b/examples/etsi_iot_01.c @@ -743,7 +743,7 @@ main(int argc, char **argv) { if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME_SEC ) { /* set timeout if there is a pdu to send before our automatic timeout occurs */ - tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) << 10; + tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; timeout = &tv; } else { diff --git a/examples/rd.c b/examples/rd.c index 4605d640..9c6f1e32 100644 --- a/examples/rd.c +++ b/examples/rd.c @@ -685,7 +685,7 @@ main(int argc, char **argv) { if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME ) { /* set timeout if there is a pdu to send before our automatic timeout occurs */ - tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) << 10; + tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; timeout = &tv; } else { diff --git a/examples/server.c b/examples/server.c index d910358d..613c52d0 100644 --- a/examples/server.c +++ b/examples/server.c @@ -394,7 +394,7 @@ main(int argc, char **argv) { if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME ) { /* set timeout if there is a pdu to send before our automatic timeout occurs */ - tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) << 10; + tv.tv_usec = ((nextpdu->t - now) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; timeout = &tv; } else {