From: Guilherme Maciel Ferreira Date: Tue, 28 Feb 2012 00:02:31 +0000 (-0300) Subject: Code improvement: X-Git-Tag: v1.5~1^2~24 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=1513bb781afb97724df383442eaaefce63c9ceb9;p=pingcheck Code improvement: - using STL rotate algorithm; - moved part of ping_done_handler() method to another method to improve readability. --- 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;