Skip to content

Commit 674a465

Browse files
author
Tero Heinonen
authored
Delete transaction if message is non-confirmable (#83)
* 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
1 parent 29bfb78 commit 674a465

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

source/coap_message_handler.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t se
337337
transaction_ptr->options = options;
338338
memcpy(transaction_ptr->remote_address, destination_addr, 16);
339339
transaction_ptr->remote_port = destination_port;
340+
transaction_ptr->req_msg_type = msg_type;
340341
memset(&request, 0, sizeof(request));
341342
dst_addr.addr_ptr = (uint8_t *) destination_addr; // Cast away const and trust that nsdl doesn't modify...
342343
dst_addr.addr_len = 16;

source/coap_service_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static uint8_t coap_tx_function(uint8_t *data_ptr, uint16_t data_len, sn_nsdl_ad
188188
memcpy(transaction_ptr->data_ptr, data_ptr, data_len);
189189
transaction_ptr->data_len = data_len;
190190
}
191-
} else if ((ret_val == -1) || (transaction_ptr->resp_cb == NULL)) {
191+
} else if ((ret_val == -1) || (!transaction_ptr->resp_cb && transaction_ptr->req_msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE)) {
192192
transaction_delete(transaction_ptr);
193193
}
194194

@@ -300,7 +300,7 @@ static void sec_done_cb(int8_t socket_id, uint8_t address[static 16], uint16_t p
300300
ns_dyn_mem_free(transaction_ptr->data_ptr);
301301
transaction_ptr->data_ptr = NULL;
302302
transaction_ptr->data_len = 0;
303-
if (transaction_ptr->resp_cb == NULL) {
303+
if (!transaction_ptr->resp_cb && transaction_ptr->req_msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) {
304304
transaction_delete(transaction_ptr);
305305
}
306306
}

0 commit comments

Comments
 (0)