From 37699fd058f42284bf48902b1ce03bcc706989d0 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 6 Mar 2014 15:38:37 +0000 Subject: [PATCH] Cancel retransmission of messages when response has arrived. In case the ACK of a separate message is lost, the request would be retransmitted until the maximum number of transmissions is reached because the response usually has a different messsage id. The matching at this point is done based on the response's source address and token. --- net.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net.c b/net.c index ea9ab0e7..d267b6ed 100644 --- a/net.c +++ b/net.c @@ -1448,12 +1448,20 @@ handle_response(coap_context_t *context, /* First acknowledge incoming response if it is a CON message. Note * that the necessary checks are done in coap_send_ack(). */ - if (rcvd->pdu->hdr->code == COAP_RESPONSE_CODE(731) - && !coap_cancel(context, rcvd)) { - - coap_send_rst(context, &rcvd->remote, rcvd->pdu); + if (rcvd->pdu->hdr->code == COAP_RESPONSE_CODE(731)) { + if (!coap_cancel(context, rcvd)) { + coap_send_rst(context, &rcvd->remote, rcvd->pdu); + } else { + coap_send_ack(context, &rcvd->remote, rcvd->pdu); + } } else { - coap_send_ack(context, &rcvd->remote, rcvd->pdu); + /* In a lossy context, the ACK of a separate response may have + * been lost, so we need to stop retransmitting requests with the + * same token. + */ + coap_cancel_all_messages(context, &rcvd->remote, + rcvd->pdu->hdr->token, + rcvd->pdu->hdr->token_length); } /* Call application-specific reponse handler when available. */