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

net/coap: specify timeout in milliseconds

This allows for more flexibility when choosing timeouts.
This commit is contained in:
Benjamin Valentin 2022-01-05 22:38:16 +01:00
parent 6f161569f4
commit d680743fe9
5 changed files with 18 additions and 18 deletions

View File

@ -183,16 +183,16 @@ extern "C" {
* @{
*/
/**
* @brief Timeout in seconds for a response to a confirmable request
* @brief Timeout in milliseconds for a response to a confirmable request
*
* This value is for the response to the *initial* confirmable message. The
* timeout doubles for subsequent retries. To avoid synchronization of resends
* across hosts, the actual timeout is chosen randomly between
* @ref CONFIG_COAP_ACK_TIMEOUT and
* (@ref CONFIG_COAP_ACK_TIMEOUT * @ref CONFIG_COAP_RANDOM_FACTOR_1000 / 1000).
* @ref CONFIG_COAP_ACK_TIMEOUT_MS and
* (@ref CONFIG_COAP_ACK_TIMEOUT_MS * @ref CONFIG_COAP_RANDOM_FACTOR_1000 / 1000).
*/
#ifndef CONFIG_COAP_ACK_TIMEOUT
#define CONFIG_COAP_ACK_TIMEOUT (2U)
#ifndef CONFIG_COAP_ACK_TIMEOUT_MS
#define CONFIG_COAP_ACK_TIMEOUT_MS (2000U)
#endif
/**
@ -202,7 +202,7 @@ extern "C" {
* ([RFC 7252, section 4.2](https://tools.ietf.org/html/rfc7252#section-4.2))
* multiplied by 1000, to avoid floating point arithmetic.
*
* See @ref CONFIG_COAP_ACK_TIMEOUT
* See @ref CONFIG_COAP_ACK_TIMEOUT_MS
*/
#ifndef CONFIG_COAP_RANDOM_FACTOR_1000
#define CONFIG_COAP_RANDOM_FACTOR_1000 (1500)

View File

@ -531,7 +531,7 @@ extern "C" {
* In normal operations the timeout between retransmissions doubles. When
* CONFIG_GCOAP_NO_RETRANS_BACKOFF is defined this doubling does not happen.
*
* @see CONFIG_COAP_ACK_TIMEOUT
* @see CONFIG_COAP_ACK_TIMEOUT_MS
*/
#define CONFIG_GCOAP_NO_RETRANS_BACKOFF
#endif

View File

@ -18,15 +18,15 @@ menuconfig KCONFIG_COAP
if KCONFIG_COAP
config COAP_ACK_TIMEOUT
int "Timeout in seconds for a response to a confirmable request"
default 2
config COAP_ACK_TIMEOUT_MS
int "Timeout in milliseconds for a response to a confirmable request"
default 2000
help
This value is for the response to the initial confirmable message. The
timeout doubles for subsequent retries. To avoid synchronization of
resends across hosts, the actual timeout is chosen randomly between
@ref CONFIG_COAP_ACK_TIMEOUT and
(@ref CONFIG_COAP_ACK_TIMEOUT * @ref CONFIG_COAP_RANDOM_FACTOR_1000 / 1000).
@ref CONFIG_COAP_ACK_TIMEOUT_MS and
(@ref CONFIG_COAP_ACK_TIMEOUT_MS * @ref CONFIG_COAP_RANDOM_FACTOR_1000 / 1000).
The default of 2 seconds is taken from
[RFC 7252, section 4.8](https://tools.ietf.org/html/rfc7252#section-4.8).

View File

@ -47,7 +47,7 @@
#define NO_IMMEDIATE_REPLY (-1)
/* End of the range to pick a random timeout */
#define TIMEOUT_RANGE_END (CONFIG_COAP_ACK_TIMEOUT * CONFIG_COAP_RANDOM_FACTOR_1000 / 1000)
#define TIMEOUT_RANGE_END (CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000 / 1000)
/* Internal functions */
static void *_event_loop(void *arg);
@ -472,9 +472,9 @@ static void _on_resp_timeout(void *arg) {
#else
unsigned i = CONFIG_COAP_MAX_RETRANSMIT - memo->send_limit;
#endif
uint32_t timeout = ((uint32_t)CONFIG_COAP_ACK_TIMEOUT << i) * MS_PER_SEC;
uint32_t timeout = (uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS << i;
#if CONFIG_COAP_RANDOM_FACTOR_1000 > 1000
uint32_t end = ((uint32_t)TIMEOUT_RANGE_END << i) * MS_PER_SEC;
uint32_t end = (uint32_t)TIMEOUT_RANGE_END << i;
timeout = random_uint32_range(timeout, end);
#endif
event_timeout_set(&memo->resp_evt_tmout, timeout);
@ -1158,9 +1158,9 @@ ssize_t gcoap_req_send(const uint8_t *buf, size_t len,
}
if (memo->msg.data.pdu_buf) {
memo->send_limit = CONFIG_COAP_MAX_RETRANSMIT;
timeout = (uint32_t)CONFIG_COAP_ACK_TIMEOUT * MS_PER_SEC;
timeout = (uint32_t)CONFIG_COAP_ACK_TIMEOUT_MS;
#if CONFIG_COAP_RANDOM_FACTOR_1000 > 1000
timeout = random_uint32_range(timeout, TIMEOUT_RANGE_END * MS_PER_SEC);
timeout = random_uint32_range(timeout, TIMEOUT_RANGE_END);
#endif
memo->state = GCOAP_MEMO_RETRANSMIT;
}

View File

@ -49,7 +49,7 @@ ssize_t nanocoap_request(sock_udp_t *sock, coap_pkt_t *pkt, size_t len)
/* TODO: timeout random between between ACK_TIMEOUT and (ACK_TIMEOUT *
* ACK_RANDOM_FACTOR) */
uint32_t timeout = CONFIG_COAP_ACK_TIMEOUT * US_PER_SEC;
uint32_t timeout = CONFIG_COAP_ACK_TIMEOUT_MS * US_PER_MS;
/* add 1 for initial transmit */
unsigned tries_left = CONFIG_COAP_MAX_RETRANSMIT + 1;