aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-03-04 21:21:25 +0200
committerRiccardo Spagni <ric@spagni.net>2019-03-04 21:21:25 +0200
commit722a856d7e48cf17d59f164490b7d35ddf1b25fb (patch)
treeef4697013c3f7a34a6ccf5077f806229838d4ecd /contrib/epee/src
parentMerge pull request #5092 (diff)
parentnetwork_throttle: use circular_buffer where appropriate (diff)
downloadmonero-722a856d7e48cf17d59f164490b7d35ddf1b25fb.tar.xz
Merge pull request #5096
7c3ade44 network_throttle: use circular_buffer where appropriate (moneromooo-monero)
Diffstat (limited to 'contrib/epee/src')
-rw-r--r--contrib/epee/src/network_throttle-detail.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/contrib/epee/src/network_throttle-detail.cpp b/contrib/epee/src/network_throttle-detail.cpp
index d2e776df0..0b42402bd 100644
--- a/contrib/epee/src/network_throttle-detail.cpp
+++ b/contrib/epee/src/network_throttle-detail.cpp
@@ -135,6 +135,7 @@ network_throttle::network_throttle(const std::string &nameshort, const std::stri
m_slot_size = 1.0; // hard coded in few places
m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle
m_last_sample_time = 0;
+ m_history.resize(m_window_size);
}
void network_throttle::set_name(const std::string &name)
@@ -168,8 +169,7 @@ void network_throttle::tick()
{
_dbg3("Moving counter buffer by 1 second " << last_sample_time_slot << " < " << current_sample_time_slot << " (last time " << m_last_sample_time<<")");
// rotate buffer
- for (size_t i=m_history.size()-1; i>=1; --i) m_history[i] = m_history[i-1];
- m_history[0] = packet_info();
+ m_history.push_front(packet_info());
if (! m_any_packet_yet)
{
m_last_sample_time = time_now;
@@ -191,7 +191,7 @@ void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_s
calculate_times_struct cts ; calculate_times(packet_size, cts , false, -1);
calculate_times_struct cts2; calculate_times(packet_size, cts2, false, 5);
- m_history[0].m_size += packet_size;
+ m_history.front().m_size += packet_size;
std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends;
std::string history_str = oss.str();