From 070585ab3dca7655ff8a714a992a0ba15be88a18 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 1 Sep 2023 23:20:03 +0200 Subject: [PATCH] remeber the first sending transfer that could not send any packets and start there next iterate --- solanaceae/ngc_ft1/ngcft1.cpp | 13 +++++++++++-- solanaceae/ngc_ft1/ngcft1.hpp | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/solanaceae/ngc_ft1/ngcft1.cpp b/solanaceae/ngc_ft1/ngcft1.cpp index 101a5e0..dc723f4 100644 --- a/solanaceae/ngc_ft1/ngcft1.cpp +++ b/solanaceae/ngc_ft1/ngcft1.cpp @@ -286,10 +286,19 @@ void NGCFT1::iteratePeer(float time_delta, uint32_t group_number, uint32_t peer_ auto timeouts = peer.cca->getTimeouts(); std::set timeouts_set{timeouts.cbegin(), timeouts.cend()}; + int64_t can_packet_size {peer.cca->canSend()}; // might get more space while iterating (time) + + // change iterat start position to not starve transfers in the back + size_t iterated_count = 0; + bool last_send_found = false; + for (size_t idx = peer.next_send_transfer_send_idx; iterated_count < peer.send_transfers.size(); idx++, iterated_count++) { + idx = idx % peer.send_transfers.size(); - for (size_t idx = 0; idx < peer.send_transfers.size(); idx++) { if (peer.send_transfers.at(idx).has_value()) { - int64_t can_packet_size {peer.cca->canSend()}; // might get more space while iterating (time) + if (!last_send_found && can_packet_size <= 0) { + peer.next_send_transfer_send_idx = idx; + last_send_found = true; // only set once + } updateSendTransfer(time_delta, group_number, peer_number, peer, idx, timeouts_set, can_packet_size); } } diff --git a/solanaceae/ngc_ft1/ngcft1.hpp b/solanaceae/ngc_ft1/ngcft1.hpp index b07119d..0c51c72 100644 --- a/solanaceae/ngc_ft1/ngcft1.hpp +++ b/solanaceae/ngc_ft1/ngcft1.hpp @@ -188,6 +188,7 @@ class NGCFT1 : public ToxEventI, public NGCEXTEventI, public NGCFT1EventProvider }; std::array, 256> send_transfers; size_t next_send_transfer_idx {0}; // next id will be 0 + size_t next_send_transfer_send_idx {0}; }; std::map peers; };