Skip to content

Commit

Permalink
net/coap: Move COAP_ACK_TIMEOUT to 'CONFIG' namespace
Browse files Browse the repository at this point in the history
COAP_ACK_TIMEOUT is moved to the compile time configuration macro
namespace.
  • Loading branch information
leandrolanzieri committed Apr 24, 2020
1 parent e9d2fdb commit 072a0d8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions sys/include/net/coap.h
Expand Up @@ -180,11 +180,11 @@ extern "C" {
* 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 COAP_ACK_TIMEOUT and
* (@ref COAP_ACK_TIMEOUT * @ref COAP_RANDOM_FACTOR_1000 / 1000).
* @ref CONFIG_COAP_ACK_TIMEOUT and
* (@ref CONFIG_COAP_ACK_TIMEOUT * @ref COAP_RANDOM_FACTOR_1000 / 1000).
*/
#ifndef COAP_ACK_TIMEOUT
#define COAP_ACK_TIMEOUT (2U)
#ifndef CONFIG_COAP_ACK_TIMEOUT
#define CONFIG_COAP_ACK_TIMEOUT (2U)
#endif

/**
Expand All @@ -194,7 +194,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 COAP_ACK_TIMEOUT
* See @ref CONFIG_COAP_ACK_TIMEOUT
*/
#ifndef COAP_RANDOM_FACTOR_1000
#define COAP_RANDOM_FACTOR_1000 (1500)
Expand Down
2 changes: 1 addition & 1 deletion sys/include/net/gcoap.h
Expand Up @@ -517,7 +517,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 COAP_ACK_TIMEOUT
* @see CONFIG_COAP_ACK_TIMEOUT
*/
#define CONFIG_GCOAP_NO_RETRANS_BACKOFF
#endif
Expand Down
6 changes: 3 additions & 3 deletions sys/net/application_layer/gcoap/gcoap.c
Expand Up @@ -42,7 +42,7 @@
#define GCOAP_RESOURCE_NO_PATH -2

/* End of the range to pick a random timeout */
#define TIMEOUT_RANGE_END (COAP_ACK_TIMEOUT * COAP_RANDOM_FACTOR_1000 / 1000)
#define TIMEOUT_RANGE_END (CONFIG_COAP_ACK_TIMEOUT * COAP_RANDOM_FACTOR_1000 / 1000)

/* Internal functions */
static void *_event_loop(void *arg);
Expand Down Expand Up @@ -249,7 +249,7 @@ static void _on_resp_timeout(void *arg) {
#else
unsigned i = COAP_MAX_RETRANSMIT - memo->send_limit;
#endif
uint32_t timeout = ((uint32_t)COAP_ACK_TIMEOUT << i) * US_PER_SEC;
uint32_t timeout = ((uint32_t)CONFIG_COAP_ACK_TIMEOUT << i) * US_PER_SEC;
#if COAP_RANDOM_FACTOR_1000 > 1000
uint32_t end = ((uint32_t)TIMEOUT_RANGE_END << i) * US_PER_SEC;
timeout = random_uint32_range(timeout, end);
Expand Down Expand Up @@ -773,7 +773,7 @@ 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;
timeout = (uint32_t)CONFIG_COAP_ACK_TIMEOUT * US_PER_SEC;
#if COAP_RANDOM_FACTOR_1000 > 1000
timeout = random_uint32_range(timeout, TIMEOUT_RANGE_END * US_PER_SEC);
#endif
Expand Down
2 changes: 1 addition & 1 deletion sys/net/application_layer/nanocoap/sock.c
Expand Up @@ -48,7 +48,7 @@ ssize_t nanocoap_request(coap_pkt_t *pkt, sock_udp_ep_t *local, sock_udp_ep_t *r

/* TODO: timeout random between between ACK_TIMEOUT and (ACK_TIMEOUT *
* ACK_RANDOM_FACTOR) */
uint32_t timeout = COAP_ACK_TIMEOUT * US_PER_SEC;
uint32_t timeout = CONFIG_COAP_ACK_TIMEOUT * US_PER_SEC;
unsigned tries_left = COAP_MAX_RETRANSMIT + 1; /* add 1 for initial transmit */
while (tries_left) {

Expand Down
2 changes: 1 addition & 1 deletion sys/suit/transport/coap.c
Expand Up @@ -136,7 +136,7 @@ static 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 = COAP_ACK_TIMEOUT * US_PER_SEC;
uint32_t timeout = CONFIG_COAP_ACK_TIMEOUT * US_PER_SEC;
uint32_t deadline = deadline_from_interval(timeout);

/* add 1 for initial transmit */
Expand Down

0 comments on commit 072a0d8

Please sign in to comment.