]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/srvrec.cc
Merge commit 'e2073b0276226b625897ef475f225bf8f508719e' as 'triehash'
[apt.git] / apt-pkg / contrib / srvrec.cc
index 9af2826533ab5373c1183510d49f8a5a1d3511dc..327e59937eda49b4bfdaa66efae58f4ead07efbd 100644 (file)
@@ -16,6 +16,7 @@
 #include <time.h>
 
 #include <algorithm>
+#include <tuple>
 
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/error.h>
 #include "srvrec.h"
 
 
+bool SrvRec::operator==(SrvRec const &other) const
+{
+   return (std::tie(target, priority, weight, port) ==
+           std::tie(other.target, other.priority, other.weight, other.port));
+}
+
 bool GetSrvRecords(std::string host, int port, std::vector<SrvRec> &Result)
 {
    std::string target;
@@ -178,7 +185,7 @@ SrvRec PopFromSrvRecs(std::vector<SrvRec> &Recs)
         [&I](SrvRec const &J) { return I->priority != J.priority; });
 
    // clock seems random enough.
-   I += clock() % std::distance(I, J);
+   I += std::max(static_cast<clock_t>(0), clock()) % std::distance(I, J);
    SrvRec const selected = std::move(*I);
    Recs.erase(I);