]> AND Private Git Repository - loba.git/commitdiff
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Bug fix: credit can be negative.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 15 Mar 2012 15:46:52 +0000 (16:46 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 15 Mar 2012 15:46:52 +0000 (16:46 +0100)
E.g. when a data message comes faster than its corresponding ctrl
message.

Check that it is not negative when computing balance.

process.cpp

index 97f2a69db2e943c01bfdb6e9187856aa073db947..b5531b0ce85eff0a0a20f6f5f9ce3a1276a71d5d 100644 (file)
@@ -421,7 +421,11 @@ void process::data_send(neighbor& nb)
         else
             excess_load = real_load;
 
         else
             excess_load = real_load;
 
-        double balance = nb.get_debt() - nb.get_credit();
+        double balance;
+        if (nb.get_credit() > 0.0)
+            balance = nb.get_debt() - nb.get_credit();
+        else
+            balance = nb.get_debt();
         load_to_send = std::min(excess_load,
                                 std::max(0.0, balance));
 
         load_to_send = std::min(excess_load,
                                 std::max(0.0, balance));