From: Francis Dupont Date: Wed, 20 Jan 2016 13:23:04 +0000 (+0100) Subject: [4254] Merged #4263 fix X-Git-Tag: trac4267_base0~10^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=992f481916e7a4549445dc1c00b5fba4a29ea020;p=thirdparty%2Fkea.git [4254] Merged #4263 fix --- diff --git a/src/bin/perfdhcp/stats_mgr.h b/src/bin/perfdhcp/stats_mgr.h index ec300e2dea..1d17c6cf23 100644 --- a/src/bin/perfdhcp/stats_mgr.h +++ b/src/bin/perfdhcp/stats_mgr.h @@ -22,6 +22,7 @@ #include #include +#include namespace isc { @@ -250,6 +251,9 @@ public: /// Packet list iterator to access packets using transaction id hash. typedef typename PktListTransidHashIndex::const_iterator PktListTransidHashIterator; + /// Packet list iterator queue for removal. + typedef typename std::queue + PktListRemovalQueue; /// \brief Constructor /// @@ -438,6 +442,8 @@ public: // bucket size the better. If bucket sizes appear to big we // might want to increase number of buckets. unordered_lookup_size_sum_ += std::distance(p.first, p.second); + // Removal can be done only after the loop + PktListRemovalQueue to_remove; for (PktListTransidHashIterator it = p.first; it != p.second; ++it) { if ((*it)->getTransid() == rcvd_packet->getTransid()) { @@ -455,19 +461,30 @@ public: (static_cast(packet_period.length().fractional_seconds()) / packet_period.length().ticks_per_second()); if (drop_time_ > 0 && (period_fractional > drop_time_)) { - // The packet pointed to by 'it' is timed out so we - // have to remove it. Removal may invalidate the - // next_sent_ pointer if it points to the packet - // being removed. So, we set the next_sent_ to point - // to the next packet after removed one. This - // pointer will be further updated in the following - // iterations, if the subsequent packets are also - // timed out. - next_sent_ = eraseSent(sent_packets_.template project<0>(it)); - ++collected_; + // Push the iterator on the removal queue. + to_remove.push(it); + } } } + + // Deal with the removal queue + while (!to_remove.empty()) { + PktListTransidHashIterator it = to_remove.front(); + to_remove.pop(); + // The packet pointed to by 'it' is timed out so + // we have to remove it. + if (packet_found || !to_remove.empty()) { + eraseSent(sent_packets_.template project<0>(it)); + } else { + // Removal may invalidate the next_sent_ + // pointer if it points to the packet being + // removed. So, we set the next_sent_ to point + // to the next packet after removed one. + next_sent_ = eraseSent(sent_packets_.template project<0>(it)); + } + ++collected_; + } } if (!packet_found) { diff --git a/src/bin/perfdhcp/tests/perf_pkt4_unittest.cc b/src/bin/perfdhcp/tests/perf_pkt4_unittest.cc index 511825d35a..2add2569ca 100644 --- a/src/bin/perfdhcp/tests/perf_pkt4_unittest.cc +++ b/src/bin/perfdhcp/tests/perf_pkt4_unittest.cc @@ -68,7 +68,7 @@ public: 255, 255, 255, 255, // giaddr }; - // cppcheck-suppress variableScope + // cppcheck-suppress variableScope uint8_t v4Opts[] = { DHO_HOST_NAME, 3, 0, 1, 2, // Host name option. DHO_BOOT_SIZE, 3, 10, 11, 12, // Boot file size option