v2.0.5-rc (#41)
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good
Reviewed-on: #41
This commit is contained in:
@ -25,8 +25,8 @@
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils {
|
||||
auto compare_version_strings(std::string version1,
|
||||
std::string version2) -> std::int32_t {
|
||||
auto compare_version_strings(std::string version1, std::string version2)
|
||||
-> std::int32_t {
|
||||
|
||||
if (utils::string::contains(version1, "-")) {
|
||||
version1 = utils::string::split(version1, '-', true)[0U];
|
||||
@ -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<std::uint16_t>(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.set_option(boost::asio::ip::tcp::acceptor::linger(true, 0));
|
||||
acceptor.bind({tcp::v4(), static_cast<std::uint16_t>(check_port)},
|
||||
error_code);
|
||||
if (error_code) {
|
||||
++check_port;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
available_port = static_cast<std::uint16_t>(check_port);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (not error_code) {
|
||||
available_port = first_port;
|
||||
}
|
||||
|
||||
return not error_code;
|
||||
return false;
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_BOOST)
|
||||
|
||||
|
@ -47,82 +47,4 @@ auto create_exception(std::string_view function_name,
|
||||
return std::runtime_error(create_error_message(function_name, items));
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
void handle_debug(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_debug(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_debug(function_name, msg);
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
|
||||
void handle_error(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_error(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_error(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_exception(function_name);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_exception(function_name);
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name,
|
||||
const std::exception &ex) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_exception(function_name, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_exception(function_name, ex);
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
void handle_info(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_info(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_info(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_trace(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_trace(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_trace(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_warn(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_warn(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_warn(function_name, msg);
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
|
||||
void set_exception_handler(const i_exception_handler *handler) {
|
||||
exception_handler = handler;
|
||||
}
|
||||
} // namespace repertory::utils::error
|
||||
|
@ -19,12 +19,15 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "utils/config.hpp"
|
||||
#include "utils/error.hpp"
|
||||
|
||||
#include "utils/config.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
namespace repertory::utils::error {
|
||||
std::atomic<const i_exception_handler *> exception_handler{
|
||||
&default_exception_handler};
|
||||
&default_exception_handler,
|
||||
};
|
||||
|
||||
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
void iostream_exception_handler::handle_debug(std::string_view function_name,
|
||||
@ -238,4 +241,83 @@ void spdlog_exception_handler::handle_warn(std::string_view function_name,
|
||||
file->warn(utils::error::create_error_message(function_name, {msg}));
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_SPDLOG) && defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
|
||||
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
void handle_debug(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_debug(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_debug(function_name, msg);
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
|
||||
void handle_error(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_error(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_error(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_exception(function_name);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_exception(function_name);
|
||||
}
|
||||
|
||||
void handle_exception(std::string_view function_name,
|
||||
const std::exception &ex) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_exception(function_name, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_exception(function_name, ex);
|
||||
}
|
||||
|
||||
#if defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
void handle_info(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_info(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_info(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_trace(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_trace(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_trace(function_name, msg);
|
||||
}
|
||||
|
||||
void handle_warn(std::string_view function_name, std::string_view msg) {
|
||||
const i_exception_handler *handler{exception_handler};
|
||||
if (handler != nullptr) {
|
||||
handler->handle_warn(function_name, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
default_exception_handler.handle_warn(function_name, msg);
|
||||
}
|
||||
#endif // defined(PROJECT_ENABLE_V2_ERRORS)
|
||||
|
||||
void set_exception_handler(const i_exception_handler *handler) {
|
||||
exception_handler = handler;
|
||||
}
|
||||
} // namespace repertory::utils::error
|
||||
|
Reference in New Issue
Block a user