MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / ParseMachineList

Method ParseMachineList

src/network/linkers_socket.cpp:80–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80void Linkers::ParseMachineList(const std::string& machines, const std::string& filename) {
81 std::vector<std::string> lines;
82 if (machines.empty()) {
83 TextReader<size_t> machine_list_reader(filename.c_str(), false);
84 machine_list_reader.ReadAllLines();
85 if (machine_list_reader.Lines().empty()) {
86 Log::Fatal("Machine list file %s doesn't exist", filename.c_str());
87 }
88 lines = machine_list_reader.Lines();
89 } else {
90 lines = Common::Split(machines.c_str(), ',');
91 }
92 for (auto& line : lines) {
93 line = Common::Trim(line);
94 if (line.find_first_of("rank=") != std::string::npos) {
95 std::vector<std::string> str_after_split = Common::Split(line.c_str(), '=');
96 Common::Atoi(str_after_split[1].c_str(), &rank_);
97 continue;
98 }
99 std::vector<std::string> str_after_split = Common::Split(line.c_str(), ' ');
100 if (str_after_split.size() != 2) {
101 str_after_split = Common::Split(line.c_str(), ':');
102 if (str_after_split.size() != 2) {
103 continue;
104 }
105 }
106 if (client_ips_.size() >= static_cast<size_t>(num_machines_)) {
107 Log::Warning("machine_list size is larger than the parameter num_machines, ignoring redundant entries");
108 break;
109 }
110 str_after_split[0] = Common::Trim(str_after_split[0]);
111 str_after_split[1] = Common::Trim(str_after_split[1]);
112 client_ips_.push_back(str_after_split[0]);
113 client_ports_.push_back(atoi(str_after_split[1].c_str()));
114 }
115 if (client_ips_.empty()) {
116 Log::Fatal("Cannot find any ip and port.\n"
117 "Please check machine_list_filename or machines parameter");
118 }
119 if (client_ips_.size() != static_cast<size_t>(num_machines_)) {
120 Log::Warning("World size is larger than the machine_list size, change world size to %d", client_ips_.size());
121 num_machines_ = static_cast<int>(client_ips_.size());
122 }
123}
124
125void Linkers::TryBind(int port) {
126 Log::Info("Trying to bind port %d...", port);

Callers

nothing calls this directly

Calls 7

push_backMethod · 0.80
SplitFunction · 0.50
TrimFunction · 0.50
AtoiFunction · 0.50
emptyMethod · 0.45
ReadAllLinesMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected