1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

gcoap: don't call random_uint32_range() when COAP_ACK_VARIANCE=0

`COAP_ACK_VARIANCE` is a configurable macro, so when it is 0, the
[precondition for `random_uint32_range()`][1] is not held.

[1]: https://doc.riot-os.org/group__sys__random.html#gab6ee09e1e56df3cc78acd1fbf97bfb24
This commit is contained in:
Martine S. Lenders 2019-07-03 15:42:16 +02:00
parent e8650f5b9a
commit 1bde141697

View File

@ -134,8 +134,10 @@ static void *_event_loop(void *arg)
memo->send_limit--;
unsigned i = COAP_MAX_RETRANSMIT - memo->send_limit;
uint32_t timeout = ((uint32_t)COAP_ACK_TIMEOUT << i) * US_PER_SEC;
#if COAP_ACK_VARIANCE > 0
uint32_t variance = ((uint32_t)COAP_ACK_VARIANCE << i) * US_PER_SEC;
timeout = random_uint32_range(timeout, timeout + variance);
#endif
ssize_t bytes = sock_udp_send(&_sock, memo->msg.data.pdu_buf,
memo->msg.data.pdu_len,
@ -753,8 +755,10 @@ size_t gcoap_req_send(const uint8_t *buf, size_t len,
if (memo->msg.data.pdu_buf) {
memo->send_limit = COAP_MAX_RETRANSMIT;
timeout = (uint32_t)COAP_ACK_TIMEOUT * US_PER_SEC;
#if COAP_ACK_VARIANCE > 0
uint32_t variance = (uint32_t)COAP_ACK_VARIANCE * US_PER_SEC;
timeout = random_uint32_range(timeout, timeout + variance);
#endif
}
else {
memo->state = GCOAP_MEMO_UNUSED;