Merge pull request #340 from mrdeep1/cancel_rst_observe

Fix RST deleting observer for non-confirmable observe
This commit is contained in:
obgm authored and GitHub committed 2019-06-26 14:39:25 +02:00
commit 5f5ab48e34
3 files changed
+16 -1

No files matched your search

+1
View File
@@ -63,6 +63,7 @@ typedef struct coap_subscription_t {
* sent (in that case, the resource's partially
* dirty flag is set too) */
unsigned int has_block2:1; /**< GET request had Block2 definition */
uint16_t tid; /**< transaction id, if any, in regular host byte order */
coap_block_t block2; /**< GET request Block2 definition */
size_t token_length; /**< actual length of token */
unsigned char token[8]; /**< token used for subscription */
+14
View File
@@ -2224,6 +2224,20 @@ coap_dispatch(coap_context_t *context, coap_session_t *session,
if(sent->pdu->type==COAP_MESSAGE_CON && context->nack_handler)
context->nack_handler(context, sent->session, sent->pdu, COAP_NACK_RST, sent->id);
}
else {
/* Need to check is there is a subscription active and delete it */
RESOURCES_ITER(context->resources, r) {
coap_subscription_t *obs, *tmp;
LL_FOREACH_SAFE(r->subscribers, obs, tmp) {
if (obs->tid == pdu->tid && obs->session == session) {
coap_binary_t token = { 0, NULL };
COAP_SET_STR(&token, obs->token_length, obs->token);
coap_delete_observer(r, session, &token);
goto cleanup;
}
}
}
}
goto cleanup;
case COAP_MESSAGE_NON: /* check for unknown critical options */
+1 -1
View File
@@ -794,7 +794,7 @@ coap_notify_observers(coap_context_t *context, coap_resource_t *r) {
token.length = obs->token_length;
token.s = obs->token;
response->tid = coap_new_message_id(obs->session);
obs->tid = response->tid = coap_new_message_id(obs->session);
if ((r->flags & COAP_RESOURCE_FLAGS_NOTIFY_CON) == 0
&& obs->non_cnt < COAP_OBS_MAX_NON) {
response->type = COAP_MESSAGE_NON;