#8 - mock client accepts configuration args
This commit is contained in:
@@ -112,9 +112,25 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char** argv) {
|
||||||
const int NUM_CLIENTS = 300;
|
if(argc > 4) {
|
||||||
tw::net::Address address = {"127.0.0.1", 8101};
|
spdlog::error("Usage: {} [client_count] [host] [port]", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint32_t NUM_CLIENTS = argc > 1 ? std::strtoul(argv[1], nullptr, 10) : 300;
|
||||||
|
const std::string host = argc > 2 ? argv[2] : "127.0.0.1";
|
||||||
|
const int port = argc > 3 ? std::atoi(argv[3]) : 8101;
|
||||||
|
|
||||||
|
auto address_r = tw::net::Address::resolve(host, port);
|
||||||
|
if(!address_r) {
|
||||||
|
spdlog::error("Failed to resolve {}:{}: {}", host, port, address_r.error().message());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tw::net::Address address = address_r.value();
|
||||||
|
|
||||||
|
spdlog::info("Starting {} clients against {}", NUM_CLIENTS, address.to_string());
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
for(uint32_t i = 0; i < NUM_CLIENTS; i++) {
|
for(uint32_t i = 0; i < NUM_CLIENTS; i++) {
|
||||||
@@ -129,7 +145,7 @@ int main() {
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i < NUM_CLIENTS; i++) {
|
for(uint32_t i = 0; i < threads.size(); i++) {
|
||||||
threads[i].join();
|
threads[i].join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user