From 1513bb781afb97724df383442eaaefce63c9ceb9 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 27 Feb 2012 21:02:31 -0300 Subject: [PATCH] Code improvement: - using STL rotate algorithm; - moved part of ping_done_handler() method to another method to improve readability. --- src/host/pingrotate.cpp | 10 ++++++++-- src/host/pingrotate.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/host/pingrotate.cpp b/src/host/pingrotate.cpp index c22fbd3..9e9acc0 100644 --- a/src/host/pingrotate.cpp +++ b/src/host/pingrotate.cpp @@ -20,6 +20,8 @@ #include "host/pingrotate.h" +#include + #include #include @@ -96,6 +98,11 @@ void PingRotate::ping_done_handler( bool ping_success ) { PingDoneCallback( ping_success ); + update_ping_protocol(); +} + +void PingRotate::update_ping_protocol() +{ if ( can_change_ping_protocol() ) { get_next_ping_protocol(); @@ -108,8 +115,7 @@ void PingRotate::get_next_ping_protocol() { PingProtocol ping_protocol = ProtocolList.front(); - ProtocolList.pop_front(); - ProtocolList.push_back( ping_protocol ); + rotate( ProtocolList.begin(), ++ProtocolList.begin(), ProtocolList.end() ); Ping = PingerFactory::createPinger( ping_protocol, IoService, NetworkInterfaceName ); } diff --git a/src/host/pingrotate.h b/src/host/pingrotate.h index b862417..42a3563 100644 --- a/src/host/pingrotate.h +++ b/src/host/pingrotate.h @@ -62,6 +62,7 @@ private: // void ping_done_handler( bool ping_success ); + void update_ping_protocol(); void get_next_ping_protocol(); bool can_change_ping_protocol() const; -- 1.7.1