From 2f6c0d7ca31cede646fe95785e26cf67bce2ae4f Mon Sep 17 00:00:00 2001 From: Lukas Woodtli Date: Thu, 13 Jul 2023 16:02:24 +0200 Subject: [PATCH] net: coap: Improve the handling of CoAP response code 'continue' When using block-wise transfer, call the reply callback only when the last block arrived. Signed-off-by: Lukas Woodtli --- include/zephyr/net/coap.h | 3 +++ subsys/net/lib/coap/coap.c | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/zephyr/net/coap.h b/include/zephyr/net/coap.h index d06a7b23dcd..747def6a372 100644 --- a/include/zephyr/net/coap.h +++ b/include/zephyr/net/coap.h @@ -259,6 +259,9 @@ struct coap_option { * @typedef coap_reply_t * @brief Helper function to be called when a response matches the * a pending request. + * When sending blocks, the callback is only executed when the + * reply of the last block is received. + * i.e. it is not called when the code of the reply is 'continue' (2.31). */ typedef int (*coap_reply_t)(const struct coap_packet *response, struct coap_reply *reply, diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index a4dab38eee8..5b0da6d9bc5 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1499,7 +1499,9 @@ struct coap_reply *coap_response_received( /* handle observed requests only if received in order */ if (age == -ENOENT || is_newer(r->age, age)) { r->age = age; - r->reply(response, r, from); + if (coap_header_get_code(response) != COAP_RESPONSE_CODE_CONTINUE) { + r->reply(response, r, from); + } } return r;