removed assertion in HostStatus that PingsPerformedCount <= ResolvedIpCount*NParallel...
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 26 May 2015 15:50:33 +0000 (17:50 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Tue, 26 May 2015 15:50:33 +0000 (17:50 +0200)
because that required some hacks in case we have no IP and call the ping_done_handler

CMakeLists.txt
src/host/hoststatus.cpp
src/host/pingscheduler.cpp

index 8ff46fd..b765f72 100644 (file)
@@ -1,7 +1,7 @@
 # project: definitions
 project(pingcheck)
 set(VERSION 0.5)
-set(VERSION_REVISION 1)
+set(VERSION_REVISION 2)
 set(TARGET ${PROJECT_NAME})
 
 # cmake: build options
index 7904bd1..7449a91 100644 (file)
@@ -144,7 +144,7 @@ void HostStatus::update_ping_statistics( const PingStatus &result,
     GlobalLogger.debug() << log_prefix() << "add ping with result "
         << to_string(result) << " which took " << ping_duration_ms << " ms";
 
-    BOOST_ASSERT( 1 <= ResolvedIpCount );
+    BOOST_ASSERT( 0 <= ResolvedIpCount );
     BOOST_ASSERT( 0 <= PingsPerformedCount );
     BOOST_ASSERT( PingsFailedCount <= PingsPerformedCount );
     BOOST_ASSERT( PingCongestionCount <= PingsPerformedCount );
@@ -196,16 +196,15 @@ void HostStatus::update_congestion_stats( const PingStatus &result,
 
 bool HostStatus::tried_all_resolved_ip() const
 {
-    BOOST_ASSERT( ( 0 < PingsPerformedCount ) &&
-                  ( PingsPerformedCount <= ResolvedIpCount*NParallelPingers ) );
+    BOOST_ASSERT( 0 < PingsPerformedCount );
 
-    return ( PingsPerformedCount == ResolvedIpCount*NParallelPingers );
+    return ( PingsPerformedCount >= ResolvedIpCount*NParallelPingers );
 }
 
 void HostStatus::analyze_ping_statistics()
 {
     BOOST_ASSERT( !HostAddress.empty() );
-    BOOST_ASSERT( PingsPerformedCount == ResolvedIpCount*NParallelPingers );
+    BOOST_ASSERT( PingsPerformedCount >= ResolvedIpCount*NParallelPingers );
 
     // notify if the amount of pings that failed exceed the limit
     if ( exceeded_ping_failed_limit() )
@@ -234,8 +233,7 @@ void HostStatus::increase_ping_performed_count()
 {
     ++PingsPerformedCount;
 
-    BOOST_ASSERT( ( 0 < PingsPerformedCount ) &&
-                  ( PingsPerformedCount <= ResolvedIpCount*NParallelPingers ) );
+    BOOST_ASSERT( 0 < PingsPerformedCount );
 }
 
 void HostStatus::increase_ping_failed_count()
index 7b06778..5e2707a 100644 (file)
@@ -244,11 +244,10 @@ void PingScheduler::ping_when_ready()
         GlobalLogger.info() << LogPrefix << "Not even outdated IP to ping "
             << "-- treat like a failed ping.";
 
-        // skip the ping and directly call ping_done_handler
-        HostAnalyzer.set_resolved_ip_count(1);   // must have been 0 --> failed
-             // ping would create failed assumption (nPings > nIPs)
-        ping_done_handler(PingStatus_FailureNoIP, 0);
-        HostAnalyzer.set_resolved_ip_count(0);   // set back
+        // skip the ping and directly call ping_done_handler the appropriate
+        // number of times
+        for (int count=0; count<NPingers; ++count)
+            ping_done_handler(PingStatus_FailureNoIP, 0);
     }
     else
     {
@@ -266,7 +265,6 @@ void PingScheduler::ping_when_ready()
         boost::asio::ip::address actual_ip = ip.get_ip();
         GlobalLogger.info() << LogPrefix << "pinging IP " << actual_ip
             << " with TTL " << ip.get_ttl().get_updated_value() << "s";
-        NPingersDone = 0;
         delayed_ping(boost::system::error_code(), actual_ip, 0);
     }
 }
@@ -353,6 +351,8 @@ void PingScheduler::prepare_next_ping()
     // start DNS resolve if necessary
     update_dns_resolver();
 
+    NPingersDone = 0;
+
     // schedule next ping
     int seconds_since_last_ping = (microsec_clock::universal_time()
                                             - TimeSentLastPing).total_seconds();
@@ -530,7 +530,7 @@ void PingScheduler::dns_resolve_callback(const bool was_success,
         // trust that a successfull DNS resolve means we have an IP with TTL>0
         int ip_count = Resolver->get_resolved_ip_count(!ContinueOnOutdatedIps);
         if (ip_count == 0)
-        {   // this will create trouble in HostAnalyzer
+        {
             GlobalLogger.warning() << LogPrefix
                 << "Should not have reached this case: resolve was "
                 << "successfull but still have no IPs (up-to-date="
@@ -546,8 +546,8 @@ void PingScheduler::dns_resolve_callback(const bool was_success,
             GlobalLogger.info() << LogPrefix << "Set resolved_ip_count to "
                 << ip_count << " (IPs may be outdated="
                 << ContinueOnOutdatedIps << ") --> could ping now";
-            HostAnalyzer.set_resolved_ip_count( ip_count );
         }
+        HostAnalyzer.set_resolved_ip_count( ip_count );
         ping_when_ready();
     }
     else