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:
parent
2a934c9434
commit
782910ade4
@ -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);
|
CONFIG_COAP_ACK_TIMEOUT_MS * CONFIG_COAP_RANDOM_FACTOR_1000);
|
||||||
uint32_t deadline = _deadline_from_interval(timeout);
|
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 */
|
/* check if we expect a reply */
|
||||||
const bool confirmable = coap_get_type(pkt) == COAP_TYPE_CON;
|
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 */
|
/* Create the first payload snip from the request buffer */
|
||||||
iolist_t head = {
|
iolist_t head = {
|
||||||
.iol_next = pkt->snips,
|
.iol_next = pkt->snips,
|
||||||
@ -140,13 +140,14 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
|
|||||||
while (1) {
|
while (1) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_REQUEST_SEND:
|
case STATE_REQUEST_SEND:
|
||||||
DEBUG("nanocoap: send %u bytes (%u tries left)\n",
|
if (tries_left == 0) {
|
||||||
(unsigned)iolist_size(&head), tries_left);
|
|
||||||
|
|
||||||
if (--tries_left == 0) {
|
|
||||||
DEBUG("nanocoap: maximum retries reached\n");
|
DEBUG("nanocoap: maximum retries reached\n");
|
||||||
return -ETIMEDOUT;
|
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);
|
res = sock_udp_sendv(sock, &head, NULL);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
@ -191,7 +192,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt,
|
|||||||
}
|
}
|
||||||
res = tmp;
|
res = tmp;
|
||||||
if (res == -ETIMEDOUT) {
|
if (res == -ETIMEDOUT) {
|
||||||
DEBUG("nanocoap: timeout, %u retries left\n", tries_left - 1);
|
DEBUG("nanocoap: timeout waiting for response\n");
|
||||||
timeout *= 2;
|
timeout *= 2;
|
||||||
deadline = _deadline_from_interval(timeout);
|
deadline = _deadline_from_interval(timeout);
|
||||||
state = STATE_REQUEST_SEND;
|
state = STATE_REQUEST_SEND;
|
||||||
|
Loading…
Reference in New Issue
Block a user