From f00be554cc65e5cdbcc5b6f07d454d82f70223a1 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 15 Sep 2020 10:10:11 +0200 Subject: [PATCH] net.c: Fix fail_cnt reset on empty ACK coap_touch_observer() must be called on empty ACKs before leaving the dispatch function. Fixes #550 [1] [1] https://github.com/obgm/libcoap/issues/550 --- src/net.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net.c b/src/net.c index 20d0226b..ccbf0157 100644 --- a/src/net.c +++ b/src/net.c @@ -2647,9 +2647,6 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, /* Flush out any entries on session->delayqueue */ coap_session_connected(session); } - if (pdu->code == 0) - goto cleanup; - /* if sent code was >= 64 the message might have been a * notification. Then, we must flag the observer to be alive * by setting obs->fail_cnt = 0. */ @@ -2658,6 +2655,11 @@ coap_dispatch(coap_context_t *context, coap_session_t *session, { sent->pdu->token_length, sent->pdu->token }; coap_touch_observer(context, sent->session, &token); } + + /* an empty ACK needs no further handling */ + if (pdu->code == 0) + goto cleanup; + break; case COAP_MESSAGE_RST: