From ee1cdeaecad1610dfcc661a6651deef6290a4ae9 Mon Sep 17 00:00:00 2001 From: Martin Slachta Date: Wed, 5 Aug 2026 19:00:57 +0200 Subject: [PATCH] #8 - mock client accepts configuration args --- modules/mock_client/src/main.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/modules/mock_client/src/main.cpp b/modules/mock_client/src/main.cpp index d24124c..03a7348 100644 --- a/modules/mock_client/src/main.cpp +++ b/modules/mock_client/src/main.cpp @@ -112,9 +112,25 @@ public: } }; -int main() { - const int NUM_CLIENTS = 300; - tw::net::Address address = {"127.0.0.1", 8101}; +int main(int argc, char** argv) { + if(argc > 4) { + 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 threads; for(uint32_t i = 0; i < NUM_CLIENTS; i++) { @@ -129,7 +145,7 @@ int main() { 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(); }