mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-21 14:59:06 +03:00
introduce partiallydirty resources and dirty subscriptions
this change spreads the concept of "dirty" from resources to subscriptions. this allows queuing up notifications in case not all of them can be transmitted at the same time (which can happen due to constraints in pdu or node space). when a dirty resource's notifications can not be sent, the resource is marked as partiallydirty, and on the subscriptions that could not be sent out, the dirty flag is set. they get cleared later when coap_notify_observers gets run again, as it not only looks for dirty, but also for partiallydirty resources. note that there is currently no facility that prevents that all the nodes get assigned to the send queue, leaving no room for receiving packages (which happens in mass notifications, blocks all incoming packages and is only resolved by the transmissions timing out). my current test setup always leaves at least one node free for reception by over-allocating and freeing a node on sending.
This commit is contained in:
1 parent
4951e368a1
commit
42296f73f5
3 files changed
+22
-3
No files matched your search
+20
-3
@@ -570,18 +570,28 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
|
||||
assert(h); /* we do not allow subscriptions if no
|
||||
* GET handler is defined */
|
||||
|
||||
if (r->observable && r->dirty) {
|
||||
if (r->observable && (r->dirty || r->partiallydirty)) {
|
||||
r->partiallydirty = 0;
|
||||
for (obs = list_head(r->subscribers); obs; obs = list_item_next(obs)) {
|
||||
if (r->dirty == 0 && obs->dirty == 0)
|
||||
/* running this resource due to partiallydirty, but this observation's notification was already enqueued */
|
||||
continue;
|
||||
|
||||
coap_tid_t tid = COAP_INVALID_TID;
|
||||
obs->dirty = 0;
|
||||
/* initialize response */
|
||||
response = coap_pdu_init(COAP_MESSAGE_CON, 0, 0, COAP_MAX_PDU_SIZE);
|
||||
if (!response) {
|
||||
debug("coap_check_notify: pdu init failed\n");
|
||||
obs->dirty = 1;
|
||||
r->partiallydirty = 1;
|
||||
debug("coap_check_notify: pdu init failed, resource stays partially dirty\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!coap_add_token(response, obs->token_length, obs->token)) {
|
||||
debug("coap_check_notify: cannot add token\n");
|
||||
obs->dirty = 1;
|
||||
r->partiallydirty = 1;
|
||||
debug("coap_check_notify: cannot add token, resource stays partially dirty\n");
|
||||
coap_delete_pdu(response);
|
||||
continue;
|
||||
}
|
||||
@@ -608,6 +618,13 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
|
||||
|
||||
if (COAP_INVALID_TID == tid || response->hdr->type != COAP_MESSAGE_CON)
|
||||
coap_delete_pdu(response);
|
||||
if (COAP_INVALID_TID == tid)
|
||||
{
|
||||
debug("coap_check_notify: sending failed, resource stays partially dirty\n");
|
||||
obs->dirty = 1;
|
||||
r->partiallydirty = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Increment value for next Observe use. */
|
||||
|
||||
@@ -56,6 +56,7 @@ typedef struct coap_attr_t {
|
||||
|
||||
typedef struct coap_resource_t {
|
||||
unsigned int dirty:1; /**< set to 1 if resource has changed */
|
||||
unsigned int partiallydirty:1; /**< set to 1 if some subscribers have not yet been notified of the last change */
|
||||
unsigned int observable:1; /**< can be observed */
|
||||
unsigned int cacheable:1; /**< can be cached */
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ typedef struct coap_subscription_t {
|
||||
unsigned int non:1; /**< send non-confirmable notifies if @c 1 */
|
||||
unsigned int non_cnt:4; /**< up to 15 non-confirmable notifies allowed */
|
||||
unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */
|
||||
unsigned int dirty:1; /**< set if the notification temporarily could not be sent (in that case, the resource's partiallydirty flag is set too) */
|
||||
|
||||
size_t token_length; /**< actual length of token */
|
||||
unsigned char token[8]; /**< token used for subscription */
|
||||
|
||||
Reference in new issue
Block a user