From 1d1e20869e13f7b710b7e39dc0589cffc3fd082f Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Fri, 8 Jul 2011 10:54:38 -0400 Subject: [PATCH] PR 12917 - Implement Compile-Server/Client Versioning - Rework - Prefer newer servers when selecting servers from a list. --- csclient.cxx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/csclient.cxx b/csclient.cxx index 8aae702af..d7b38f88d 100644 --- a/csclient.cxx +++ b/csclient.cxx @@ -120,6 +120,16 @@ struct compile_server_info return false; return true; } + + // Used to sort servers by preference for order of contact. The preferred server is + // "less" than the other one. + bool operator< (const compile_server_info &that) const + { + // Prefer servers with a later (higher) version number. + cs_protocol_version this_version (this->version.c_str ()); + cs_protocol_version that_version (that.version.c_str ()); + return that_version < this_version; + } }; ostream &operator<< (ostream &s, const compile_server_info &i); @@ -1071,6 +1081,18 @@ compile_server_client::package_request () return rc; } +static void +preferred_order (vector &servers) +{ + // Sort the given list of servers into the preferred order for contacting. + // Don't bother if there are less than 2 servers in the list. + if (servers.size () < 2) + return; + + // Sort the list using compile_server_info::operator< + sort (servers.begin (), servers.end ()); +} + int compile_server_client::find_and_connect_to_server () { @@ -1123,6 +1145,9 @@ compile_server_client::find_and_connect_to_server () return 1; } + // Sort the list of servers into a preferred order. + preferred_order (server_list); + // Now try each of the identified servers in turn. int rc = compile_using_server (server_list); if (rc == SUCCESS) @@ -1751,6 +1776,9 @@ query_server_status (systemtap_session &s, const string &status_string) get_all_server_info (s, servers); keep_common_server_info (raw_servers, servers); + // Sort the list of servers into a preferred order. + preferred_order (servers); + // Print the server information. Skip the empty entry at the head of the list. clog << _F("Systemtap Compile Server Status for '%s'", working_string.c_str()) << endl; bool found = false; -- 2.43.5