bugfix: add flag for CON/NON notification messages

Two new flags COAP_RESOURCE_FLAGS_NOTIFY_NON and
COAP_RESOURCE_FLAGS_NOTIFY_CON have been added to control the
message type for notifications to send. The default type is
COAP_RESOURCE_FLAGS_NOTIFY_NON which can be changed with the
function coap_resource_set_mode().

The observer-specific flag has been removed.
This commit is contained in:
Olaf Bergmann committed 2015-09-29 09:03:18 +02:00
1 parent 11daf0545a
commit 683337890e
5 files changed
+18 -6

No files matched your search

-1
View File
@@ -1429,7 +1429,6 @@ handle_request(coap_context_t *context, coap_queue_t *node) {
subscription = coap_add_observer(resource, &node->local_if,
&node->remote, &token);
if (subscription) {
subscription->non = node->pdu->hdr->type == COAP_MESSAGE_NON;
coap_touch_observer(context, &node->remote, &token);
}
}
+3 -2
View File
@@ -1,6 +1,6 @@
/* resource.c -- generic resource handling
*
* Copyright (C) 2010--2014 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2010--2015 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
@@ -646,7 +646,8 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
token.s = obs->token;
response->hdr->id = coap_new_message_id(context);
if (obs->non && obs->non_cnt < COAP_OBS_MAX_NON) {
if ((r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) == 0
&& obs->non_cnt < COAP_OBS_MAX_NON) {
response->hdr->type = COAP_MESSAGE_NON;
} else {
response->hdr->type = COAP_MESSAGE_CON;