mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-05 20:02:19 +03:00
added coap_adjust_basetime() to advance sendqueue_basetime
This commit is contained in:
1 parent
b22789b4d9
commit
e1152dfd7c
2 files changed
+57
-12
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/* net.c -- CoAP network interface
|
||||
*
|
||||
* Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
|
||||
* Copyright (C) 2010--2013 Olaf Bergmann <bergmann@tzi.org>
|
||||
*
|
||||
* This file is part of the CoAP library libcoap. Please see
|
||||
* README for terms of use.
|
||||
@@ -87,6 +87,43 @@ int print_wellknown(coap_context_t *, unsigned char *, size_t *, coap_opt_t *);
|
||||
void coap_handle_failed_notify(coap_context_t *, const coap_address_t *,
|
||||
const str *);
|
||||
|
||||
unsigned int
|
||||
coap_adjust_basetime(coap_context_t *ctx, coap_tick_t now) {
|
||||
unsigned int result = 0;
|
||||
coap_tick_diff_t delta = now - ctx->sendqueue_basetime;
|
||||
|
||||
if (ctx->sendqueue) {
|
||||
/* delta < 0 means that the new time stamp is before the old. */
|
||||
if (delta <= 0) {
|
||||
ctx->sendqueue->t -= delta;
|
||||
} else {
|
||||
/* This case is more complex: The time must be advanced forward,
|
||||
* thus possibly leading to timed out elements at the queue's
|
||||
* start. For every element that has timed out, its relative
|
||||
* time is set to zero and the result counter is increased. */
|
||||
|
||||
coap_queue_t *q = ctx->sendqueue;
|
||||
coap_tick_t t = 0;
|
||||
while (q && (t + q->t < (coap_tick_t)delta)) {
|
||||
t += q->t;
|
||||
q->t = 0;
|
||||
result++;
|
||||
q = q->next;
|
||||
}
|
||||
|
||||
/* finally adjust the first element that has not expired */
|
||||
if (q) {
|
||||
q->t = (coap_tick_t)delta - t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* adjust basetime */
|
||||
ctx->sendqueue_basetime += delta;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
coap_insert_node(coap_queue_t **queue, coap_queue_t *node) {
|
||||
coap_queue_t *p, *q;
|
||||
|
||||
Reference in new issue
Block a user