Sfoglia il codice sorgente

add sorting by priority

Michael Vogt 12 anni fa
parent
commit
8194f97685
2 ha cambiato i file con 10 aggiunte e 2 eliminazioni
  1. 7 0
      apt-pkg/contrib/srvrec.cc
  2. 3 2
      apt-pkg/contrib/srvrec.h

+ 7 - 0
apt-pkg/contrib/srvrec.cc

@@ -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;
 }

+ 3 - 2
apt-pkg/contrib/srvrec.h

@@ -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);