mirror of
https://github.com/basiliscos/syncspirit.git
synced 2026-05-02 17:42:26 +00:00
core: allow poll_timeout to be zero
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2019-2025 Ivan Baidakou
|
||||
// SPDX-FileCopyrightText: 2019-2026 Ivan Baidakou
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
@@ -151,7 +151,7 @@ static main_t make_default_config(const bfs::path &config_path, const bfs::path
|
||||
cfg.timeout = 30000;
|
||||
cfg.device_name = device;
|
||||
cfg.hasher_threads = 3;
|
||||
cfg.poll_timeout = 1;
|
||||
cfg.poll_timeout = 0;
|
||||
cfg.log_configs = {
|
||||
// log_config_t {
|
||||
// "default", spdlog::level::level_enum::trace, {"stdout"}
|
||||
|
||||
@@ -39,6 +39,32 @@ error_ptr_t positive_integer_t::validate_value() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
non_negative_integer_t::non_negative_integer_t(std::string label, std::string explanation, uint64_t value,
|
||||
uint64_t default_value)
|
||||
: property_t(std::move(label), std::move(explanation), std::to_string(value), std::to_string(default_value),
|
||||
property_kind_t::positive_integer),
|
||||
native_value{value} {}
|
||||
|
||||
error_ptr_t non_negative_integer_t::validate_value() noexcept {
|
||||
std::uint64_t r;
|
||||
auto [ptr, ec] = std::from_chars(value.data(), value.data() + value.size(), r);
|
||||
|
||||
if (ec == std::errc::invalid_argument) {
|
||||
return error_ptr_t(new std::string("not a number"));
|
||||
} else if (ec == std::errc::result_out_of_range) {
|
||||
return error_ptr_t(new std::string("too large number"));
|
||||
}
|
||||
assert(ec == std::errc());
|
||||
|
||||
if (r < 0) {
|
||||
return error_ptr_t(new std::string("not a non-negative number"));
|
||||
}
|
||||
|
||||
// all ok
|
||||
native_value = static_cast<std::uint64_t>(r);
|
||||
return {};
|
||||
}
|
||||
|
||||
integer_t::integer_t(std::string label, std::string explanation, int64_t value, int64_t default_value)
|
||||
: property_t(std::move(label), std::move(explanation), std::to_string(value), std::to_string(default_value),
|
||||
property_kind_t::positive_integer),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// SPDX-FileCopyrightText: 2024-2025 Ivan Baidakou
|
||||
// SPDX-FileCopyrightText: 2024-2026 Ivan Baidakou
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -20,6 +20,14 @@ struct positive_integer_t : property_t {
|
||||
std::uint64_t native_value;
|
||||
};
|
||||
|
||||
struct non_negative_integer_t : property_t {
|
||||
non_negative_integer_t(std::string label, std::string explanation, std::uint64_t value, std::uint64_t default_value);
|
||||
|
||||
error_ptr_t validate_value() noexcept override;
|
||||
|
||||
std::uint64_t native_value;
|
||||
};
|
||||
|
||||
struct integer_t : property_t {
|
||||
integer_t(std::string label, std::string explanation, std::int64_t value, std::int64_t default_value);
|
||||
|
||||
@@ -394,8 +402,8 @@ struct hasher_threads_t final : impl::positive_integer_t {
|
||||
void reflect_to(syncspirit::config::main_t &main) override;
|
||||
};
|
||||
|
||||
struct poll_timeout_t final : impl::positive_integer_t {
|
||||
using parent_t = impl::positive_integer_t;
|
||||
struct poll_timeout_t final : impl::non_negative_integer_t {
|
||||
using parent_t = impl::non_negative_integer_t;
|
||||
|
||||
static const char *explanation_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user