Skip to content

Commit 5f92db3

Browse files
author
Antti Yli-Tokola
committed
Add a flag to maintain backward compatibility
By default CoAP will create a copy of the whole data to be passed to application and it keeps the backward compatibility. If enabled, application must NOT free the payload when it gets the COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED status. And application must call sn_coap_protocol_block_remove() instead.
1 parent d74326e commit 5f92db3

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

features/frameworks/mbed-coap/CHANGELOG.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
# Change Log
22

3-
## [v5.0.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.0.0)
4-
**NOTE! Blockwise functionality has changed and it is not backward compatible. User is now responsible of freeing the data by calling sn_coap_protocol_block_remove() and must NOT free the payload anymore separately.**
5-
6-
Here is the change needed on application side:
3+
## [v5.1.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.0)
74

8-
```
9-
if (received_coap_message->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED) {
10-
free(received_coap_header->payload_ptr);
11-
}
5+
- Introduce SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT configuration flag.
6+
Flag is disabled by default to keep the backward compatibility in place.
7+
If flag is enabled, application must NOT free the payload when it gets the COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED status.
8+
And application must call sn_coap_protocol_block_remove() instead.
129

13-
-->
10+
-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v5.0.0...v5.1.0)
1411

15-
if (received_coap_message->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED) {
16-
// Free the block message from the CoAP list
17-
sn_nsdl_remove_coap_block(_nsdl_handle, address, received_coap_header->payload_len, received_coap_header->payload_ptr);
18-
}
19-
```
12+
## [v5.0.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.0.0)
2013

2114
- Reduce heap footprint by storing only single block when receiving a blockwise message.
15+
* User is now responsible of freeing the data by calling sn_coap_protocol_block_remove() and must not free the payload separately.
2216
- Bug fix: Request blockwise transfer if incoming payload length is too large and when it comes without block indication.
2317

2418
-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.8.1...v5.0.0)
@@ -250,4 +244,3 @@ Extend blockwise message transfer status to have states for sending as well.
250244
**New feature**
251245

252246
- Initial release of mbed-coap separated from mbed-client-c
253-

features/frameworks/mbed-coap/mbed-coap/sn_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,14 @@
260260
#define SN_COAP_BLOCKWISE_INTERNAL_BLOCK_2_HANDLING_ENABLED 1
261261
#endif
262262

263+
/**
264+
* \def SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT
265+
* \brief A heap optimization switch, which removes unnecessary copy of the blockwise data.
266+
* If enabled, application must NOT free the payload when it gets the COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED status.
267+
* Application must call sn_coap_protocol_block_remove() instead.
268+
*/
269+
#ifndef SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT
270+
#define SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT 0 /**< Disabled by default */
271+
#endif
272+
263273
#endif // SN_CONFIG_H

features/frameworks/mbed-coap/source/sn_coap_protocol.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,8 +2293,18 @@ static bool sn_coap_handle_last_blockwise(struct coap_s *handle, const sn_nsdl_a
22932293
if (!whole_payload_len) {
22942294
return false;
22952295
}
2296+
2297+
#if SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT
22962298
received_coap_msg_ptr->payload_ptr = payload_ptr;
22972299
received_coap_msg_ptr->payload_len = whole_payload_len;
2300+
#else
2301+
received_coap_msg_ptr->payload_ptr = sn_coap_protocol_malloc_copy(handle, payload_ptr, whole_payload_len);
2302+
if (received_coap_msg_ptr->payload_ptr == NULL) {
2303+
tr_error("sn_coap_handle_last_blockwise - failed to allocate whole package!");
2304+
return false;
2305+
}
2306+
received_coap_msg_ptr->payload_len = whole_payload_len;
2307+
#endif
22982308
received_coap_msg_ptr->coap_status = COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED;
22992309

23002310
return true;

0 commit comments

Comments
 (0)