From c4431b8463371d75d0b714fafd6c990d4511bb22 Mon Sep 17 00:00:00 2001 From: bugobliterator Date: Wed, 17 May 2023 12:06:55 +1000 Subject: [PATCH] update canardCleanupStaleTransfers to cleanup stale tx as well --- canard.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/canard.c b/canard.c index ee03da2..e747e77 100644 --- a/canard.c +++ b/canard.c @@ -687,6 +687,41 @@ void canardCleanupStaleTransfers(CanardInstance* ins, uint64_t current_time_usec state = canardRxFromIdx(&ins->allocator, state->next); } } + +#if CANARD_MULTI_IFACE || CANARD_ENABLE_DEADLINE + // remove stale TX transfers + CanardTxQueueItem* prev_item = ins->tx_queue, * item = ins->tx_queue; + while (item != NULL) + { +#if CANARD_MULTI_IFACE && CANARD_ENABLE_DEADLINE + if ((current_time_usec > item->frame.deadline_usec) || item->frame.iface_mask == 0) +#elif CANARD_MULTI_IFACE + if (item->frame.iface_mask == 0) +#else + if (current_time_usec > item->frame.deadline_usec) +#endif + { + if (item == ins->tx_queue) + { + ins->tx_queue = ins->tx_queue->next; + freeBlock(&ins->allocator, item); + item = ins->tx_queue; + prev_item = item; + } + else + { + prev_item->next = item->next; + freeBlock(&ins->allocator, item); + item = prev_item->next; + } + } + else + { + prev_item = item; + item = item->next; + } + } +#endif } int16_t canardDecodeScalar(const CanardRxTransfer* transfer,