Code improvement:
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 28 Feb 2012 00:02:31 +0000 (21:02 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 28 Feb 2012 10:11:02 +0000 (07:11 -0300)
- using STL rotate algorithm;
- moved part of ping_done_handler() method to another method to improve readability.

src/host/pingrotate.cpp
src/host/pingrotate.h

index c22fbd3..9e9acc0 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "host/pingrotate.h"
 
+#include <algorithm>
+
 #include <boost/assert.hpp>
 #include <boost/bind.hpp>
 
@@ -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 );
     }
index b862417..42a3563 100644 (file)
@@ -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;