1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

nanocoap_sock: only re-transmit CON messages

If a NON confirmable message is sent with a callback function,
not receiving a response in time would lead to a retransmission.

This is of course an error, as only CON messages are to be retransmitted.
This commit is contained in:
Benjamin Valentin 2022-10-29 01:42:15 +02:00
parent 2a934c9434
commit 782910ade4

View File

@ -124,12 +124,12 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000);
uint32_t deadline = _deadline_from_interval(timeout);
/* add 1 for initial transmit */
unsigned tries_left = CONFIG_COAP_MAX_RETRANSMIT + 1;
/* check if we expect a reply */
const bool confirmable = coap_get_type(pkt) == COAP_TYPE_CON;
/* add 1 for initial transmit, retry only when CONfirmable */
unsigned tries_left = confirmable * CONFIG_COAP_MAX_RETRANSMIT + 1;
/* Create the first payload snip from the request buffer */
iolist_t head = {
.iol_next = pkt->snips,
@ -140,13 +140,14 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
while (1) {
switch (state) {
case STATE_REQUEST_SEND:
DEBUG("nanocoap: send %u bytes (%u tries left)\n",
(unsigned)iolist_size(&head), tries_left);
if (--tries_left == 0) {
if (tries_left == 0) {
DEBUG("nanocoap: maximum retries reached\n");
return -ETIMEDOUT;
}
--tries_left;
DEBUG("nanocoap: send %u bytes (%u tries left)\n",
(unsigned)iolist_size(&head), tries_left);
res = sock_udp_sendv(sock, &head, NULL);
if (res <= 0) {
@ -191,7 +192,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
}
res = tmp;
if (res == -ETIMEDOUT) {
DEBUG("nanocoap: timeout, %u retries left\n", tries_left - 1);
DEBUG("nanocoap: timeout waiting for response\n");
timeout *= 2;
deadline = _deadline_from_interval(timeout);
state = STATE_REQUEST_SEND;