From 651bbb8c1bf0c014bd07c949270e8bf013efb654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Gonz=C3=A1lez?= Date: Fri, 24 Sep 2021 11:32:36 +0200 Subject: [PATCH] Refs #12161. Improving sending only one GAP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ricardo González --- src/cpp/rtps/writer/StatefulWriter.cpp | 36 +++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/cpp/rtps/writer/StatefulWriter.cpp b/src/cpp/rtps/writer/StatefulWriter.cpp index c2f21639f76..df3aea84eed 100644 --- a/src/cpp/rtps/writer/StatefulWriter.cpp +++ b/src/cpp/rtps/writer/StatefulWriter.cpp @@ -704,6 +704,7 @@ DeliveryRetCode StatefulWriter::deliver_sample_to_network( while (DeliveryRetCode::DELIVERED == ret_code && min_unsent_fragment != n_fragments + 1) { + SequenceNumber_t gap_seq_for_all = SequenceNumber_t::unknown(); locator_selector.locator_selector.reset(false); auto first_relevant_reader = matched_remote_readers_.begin(); bool inline_qos = false; @@ -735,10 +736,32 @@ DeliveryRetCode StatefulWriter::deliver_sample_to_network( // send it a personal GAP. if (SequenceNumber_t::unknown() != gap_seq) { - group.sender(this, (*remote_reader)->message_sender()); - group.add_gap(gap_seq, SequenceNumberSet_t(change->sequenceNumber), (*remote_reader)->guid()); - send_heartbeat_nts_(1u, group, disable_positive_acks_); - group.sender(this, &locator_selector); // This makes the flush_and_reset(). + if (SequenceNumber_t::unknown() == gap_seq_for_all) // Calculate if the hole is for all readers + { + History::const_iterator chit = mp_history->find_change_nts(change); + + if (chit == mp_history->changesBegin()) + { + gap_seq_for_all = gap_seq; + } + else + { + SequenceNumber_t prev = (*std::prev(chit))->sequenceNumber + 1; + + if (prev == gap_seq) + { + gap_seq_for_all = gap_seq; + } + } + } + + if (gap_seq_for_all != gap_seq) // If it is an individual GAP, sent it to repective reader. + { + group.sender(this, (*remote_reader)->message_sender()); + group.add_gap(gap_seq, SequenceNumberSet_t(change->sequenceNumber), (*remote_reader)->guid()); + send_heartbeat_nts_(1u, group, disable_positive_acks_); + group.sender(this, &locator_selector); // This makes the flush_and_reset(). + } } } else @@ -747,6 +770,11 @@ DeliveryRetCode StatefulWriter::deliver_sample_to_network( } } + if (SequenceNumber_t::unknown() != gap_seq_for_all) // Send GAP for all readers + { + group.add_gap(gap_seq_for_all, SequenceNumberSet_t(change->sequenceNumber)); + } + try { if (should_be_sent)