Support client round robin to multiple server addresses.

Change-Id: If87dc64a485b1c8a340c5f6fa39ca09d40133e30
This commit is contained in:
Peter Johnson
2016-04-08 13:31:35 -07:00
parent b8ad1de33c
commit 5ac68f74d4
12 changed files with 175 additions and 25 deletions

View File

@@ -11,7 +11,7 @@
using llvm::StringRef;
const char NetworkTable::PATH_SEPARATOR_CHAR = '/';
std::string NetworkTable::s_ip_address;
std::vector<std::string> NetworkTable::s_ip_addresses;
std::string NetworkTable::s_persistent_filename = "networktables.ini";
bool NetworkTable::s_client = false;
bool NetworkTable::s_running = false;
@@ -19,9 +19,13 @@ unsigned int NetworkTable::s_port = NT_DEFAULT_PORT;
void NetworkTable::Initialize() {
if (s_running) Shutdown();
if (s_client)
nt::StartClient(s_ip_address.c_str(), s_port);
else
if (s_client) {
std::vector<std::pair<StringRef, unsigned int>> servers;
servers.reserve(s_ip_addresses.size());
for (const auto& ip_address : s_ip_addresses)
servers.emplace_back(std::make_pair(ip_address, s_port));
nt::StartClient(servers);
} else
nt::StartServer(s_persistent_filename, "", s_port);
s_running = true;
}
@@ -50,7 +54,14 @@ void NetworkTable::SetTeam(int team) {
SetIPAddress(tmp);
}
void NetworkTable::SetIPAddress(StringRef address) { s_ip_address = address; }
void NetworkTable::SetIPAddress(StringRef address) {
s_ip_addresses.clear();
s_ip_addresses.emplace_back(address);
}
void NetworkTable::SetIPAddress(llvm::ArrayRef<std::string> addresses) {
s_ip_addresses = addresses;
}
void NetworkTable::SetPort(unsigned int port) { s_port = port; }