From a0aa4436a649f08fee4b8f10033c58fe96dd74a6 Mon Sep 17 00:00:00 2001 From: Adrian Wann Date: Wed, 6 Nov 2024 13:55:19 +1100 Subject: [PATCH] Remove unfinished packets after timeout --- src/extension/network/NUClearNetwork.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/extension/network/NUClearNetwork.cpp b/src/extension/network/NUClearNetwork.cpp index 79c993ff..778adaa1 100644 --- a/src/extension/network/NUClearNetwork.cpp +++ b/src/extension/network/NUClearNetwork.cpp @@ -851,6 +851,15 @@ namespace extension { // We have completed this packet, discard the data assemblers.erase(assemblers.find(packet.packet_id)); } + + // Check for and delete any timed out packets + for (auto it = assemblers.begin(); it != assemblers.end();) { + const auto now = std::chrono::steady_clock::now(); + const auto timeout = remote->round_trip_time * 10.0; + const auto& last_chunk_time = it->second.first; + + it = now > last_chunk_time + timeout ? assemblers.erase(it) : std::next(it); + } } } } break;