From b116fc6d79515334724c493b09740cfab1c09ebd Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 6 Nov 2013 22:34:48 +0100 Subject: [PATCH] adjust client and server example to relative timers --- examples/client.c | 8 ++++---- examples/server.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/client.c b/examples/client.c index 06acf285..bb13ded9 100644 --- a/examples/client.c +++ b/examples/client.c @@ -1112,15 +1112,15 @@ main(int argc, char **argv) { nextpdu = coap_peek_next( ctx ); coap_ticks(&now); - while ( nextpdu && nextpdu->t <= now ) { + while (nextpdu && nextpdu->t <= now - ctx->sendqueue_basetime) { coap_retransmit( ctx, coap_pop_next( ctx )); nextpdu = coap_peek_next( ctx ); } - if (nextpdu && nextpdu->t < min(obs_wait ? obs_wait : max_wait, max_wait)) { + if (nextpdu && nextpdu->t < min(obs_wait ? obs_wait : max_wait, max_wait) - now) { /* set timeout if there is a pdu to send */ - 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; + tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; + tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND; } else { /* check if obs_wait fires before max_wait */ if (obs_wait && obs_wait < max_wait) { diff --git a/examples/server.c b/examples/server.c index d08f6f7f..9c633911 100644 --- a/examples/server.c +++ b/examples/server.c @@ -398,15 +398,15 @@ main(int argc, char **argv) { nextpdu = coap_peek_next( ctx ); coap_ticks(&now); - while ( nextpdu && nextpdu->t <= now ) { + while (nextpdu && nextpdu->t <= now - ctx->sendqueue_basetime) { coap_retransmit( ctx, coap_pop_next( ctx ) ); nextpdu = coap_peek_next( ctx ); } - if ( nextpdu && nextpdu->t <= now + COAP_RESOURCE_CHECK_TIME ) { + if ( nextpdu && nextpdu->t <= 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) * 1000000 / COAP_TICKS_PER_SECOND; - tv.tv_sec = (nextpdu->t - now) / COAP_TICKS_PER_SECOND; + tv.tv_usec = ((nextpdu->t) % COAP_TICKS_PER_SECOND) * 1000000 / COAP_TICKS_PER_SECOND; + tv.tv_sec = (nextpdu->t) / COAP_TICKS_PER_SECOND; timeout = &tv; } else { tv.tv_usec = 0;