]> git.saurik.com Git - apt.git/commitdiff
add sorting by priority
authorMichael Vogt <mvo@ubuntu.com>
Tue, 20 May 2014 13:08:21 +0000 (15:08 +0200)
committerMichael Vogt <mvo@ubuntu.com>
Tue, 20 May 2014 13:08:21 +0000 (15:08 +0200)
apt-pkg/contrib/srvrec.cc
apt-pkg/contrib/srvrec.h

index d5d89fc678e2091046eba912d98efcc8a154ebd2..352a569704c23a5d41eeb5be8e3fc4b5d68f21d8 100644 (file)
@@ -12,6 +12,8 @@
 #include <arpa/nameser.h>
 #include <resolv.h>
 
+#include <algorithm>
+
 #include <apt-pkg/error.h>
 #include "srvrec.h"
 
@@ -89,5 +91,10 @@ bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result)
       Result.push_back(rec);
    }
 
+   // sort them
+   std::stable_sort(Result.begin(), Result.end());
+
+   // FIXME: implement weight selection as specified in RFC-2782
+
    return true;
 }
index 583907706b59e7950c63e7b20d4f69e6f0a7aca8..78d238c46784443e277e221fde25aaaf4e99e1b4 100644 (file)
@@ -21,8 +21,9 @@ class SrvRec
    u_int16_t weight;
    u_int16_t port;
 
-   // see rfc-2782
-   //int random;
+   bool operator<(SrvRec const &other) const { 
+      return this->priority < other.priority; 
+   }
 };
 
 bool GetSrvRecords(std::string name, std::vector<SrvRec> &Result);