From 2fcb9490c918d54afa1ef213802ef2f9887bd616 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 23 Mar 2025 18:24:40 -0500 Subject: [PATCH] updated build system --- scripts/copy_mingw64_deps.sh | 1 + support/src/utils/common.cpp | 49 ++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/scripts/copy_mingw64_deps.sh b/scripts/copy_mingw64_deps.sh index b8bb231..51cf341 100755 --- a/scripts/copy_mingw64_deps.sh +++ b/scripts/copy_mingw64_deps.sh @@ -15,6 +15,7 @@ if [ "${PROJECT_IS_MINGW}" == "1" ] && [ "${PROJECT_STATIC_LINK}" == "OFF" ]; th /mingw64/bin/libstdc++-6.dll /mingw64/bin/libwinpthread-1.dll /mingw64/bin/libzlib1.dll + /mingw64/bin/libzstd.dll /mingw64/bin/zlib1.dll ) diff --git a/support/src/utils/common.cpp b/support/src/utils/common.cpp index ff9d5bd..7a1c132 100644 --- a/support/src/utils/common.cpp +++ b/support/src/utils/common.cpp @@ -131,23 +131,46 @@ auto get_next_available_port(std::uint16_t first_port, using ip::tcp; boost::system::error_code error_code{}; - while (first_port != 0U) { - io_context ctx{}; - tcp::acceptor acceptor(ctx); - acceptor.open(tcp::v4(), error_code) || - acceptor.bind({tcp::v4(), first_port}, error_code); - if (not error_code) { - break; + + std::uint32_t check_port{first_port}; + while (check_port <= 65535U) { + { + io_context ctx{}; + tcp::socket socket(ctx); + socket.connect( + { + tcp::endpoint(ip::address_v4::loopback(), + static_cast(check_port)), + }, + error_code); + if (not error_code) { + ++check_port; + continue; + } } - ++first_port; + { + io_context ctx{}; + tcp::acceptor acceptor(ctx); + acceptor.open(tcp::v4(), error_code); + if (error_code) { + ++check_port; + continue; + } + + acceptor.bind({tcp::v4(), static_cast(check_port)}, + error_code); + if (error_code) { + ++check_port; + continue; + } + } + + available_port = static_cast(check_port); + return true; } - if (not error_code) { - available_port = first_port; - } - - return not error_code; + return false; } #endif // defined(PROJECT_ENABLE_BOOST)