Skip to content

Commit 246f431

Browse files
author
Yogesh Pande
committed
Delaying message id random initialization to later stage.
Random initialization sequence is causing start up issues in multiple platform when done at construction phase. The right thing is to delay the random initialization to later stage when the message id is actually required. This provides system to do all necessary allocation upfront without causing any random race condition at startup phase.
1 parent bf1aa5c commit 246f431

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

features/frameworks/mbed-coap/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## [v5.1.1](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.1)
4+
5+
- Delay the random initialization of message id to a later phase and not during init() so there is enough time
6+
for system to complete the rest of the initialization.
7+
8+
-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v5.1.0...v5.1.1)
9+
10+
311
## [v5.1.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.0)
412

513
- Introduce SN_COAP_REDUCE_BLOCKWISE_HEAP_FOOTPRINT configuration flag.

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,7 @@ struct coap_s *sn_coap_protocol_init(void *(*used_malloc_func_ptr)(uint16_t), vo
179179

180180
#endif /* ENABLE_RESENDINGS */
181181

182-
/* Randomize global message ID */
183-
randLIB_seed_random();
184-
message_id = randLIB_get_16bit();
185-
if (message_id == 0) {
186-
message_id = 1;
187-
}
188-
182+
message_id = 0;
189183
return handle;
190184
}
191185

@@ -2526,6 +2520,11 @@ static bool compare_address_and_port(const sn_nsdl_addr_s* left, const sn_nsdl_a
25262520

25272521
static uint16_t get_new_message_id(void)
25282522
{
2523+
if (message_id == 0) {
2524+
/* Randomize global message ID */
2525+
randLIB_seed_random();
2526+
message_id = randLIB_get_16bit();
2527+
}
25292528
message_id++;
25302529
if (message_id == 0) {
25312530
message_id = 1;

0 commit comments

Comments
 (0)