Skip to content

Commit

Permalink
Delete transaction if message is non-confirmable (ARMmbed#83)
Browse files Browse the repository at this point in the history
* Delete transaction if message is non-confirmable

* Delete transaction if message is non-confirmable

After transaction is sent, delete transaction pointer if no response callback
is defined and message type is non-confirmable
  • Loading branch information
Tero Heinonen committed Nov 30, 2017
1 parent 29bfb78 commit 674a465
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/coap_message_handler.c
Expand Up @@ -337,6 +337,7 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
transaction_ptr->options = options;
memcpy(transaction_ptr->remote_address, destination_addr, 16);
transaction_ptr->remote_port = destination_port;
transaction_ptr->req_msg_type = msg_type;
memset(&request, 0, sizeof(request));
dst_addr.addr_ptr = (uint8_t *) destination_addr; // Cast away const and trust that nsdl doesn't modify...
dst_addr.addr_len = 16;
Expand Down
4 changes: 2 additions & 2 deletions source/coap_service_api.c
Expand Up @@ -188,7 +188,7 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
memcpy(transaction_ptr->data_ptr, data_ptr, data_len);
transaction_ptr->data_len = data_len;
}
} else if ((ret_val == -1) || (transaction_ptr->resp_cb == NULL)) {
} else if ((ret_val == -1) || (!transaction_ptr->resp_cb && transaction_ptr->req_msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE)) {
transaction_delete(transaction_ptr);
}

Expand Down Expand Up @@ -300,7 +300,7 @@ static void sec_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t p
ns_dyn_mem_free(transaction_ptr->data_ptr);
transaction_ptr->data_ptr = NULL;
transaction_ptr->data_len = 0;
if (transaction_ptr->resp_cb == NULL) {
if (!transaction_ptr->resp_cb && transaction_ptr->req_msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) {
transaction_delete(transaction_ptr);
}
}
Expand Down

0 comments on commit 674a465

Please sign in to comment.