From 2e25008de35f89dd3ca8f0113d7a739b1ab4a4ee Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 5 Sep 2020 12:25:12 +0100 Subject: [PATCH] Timeouts should be treated as integer here It's not a double in the settings. It gets casted into a double later, but it's not like you can set 3.528 in the settings. --- src/app_config.cpp | 23 ++++++++++------------- src/app_config.hpp | 8 ++++---- src/evloop.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/app_config.cpp b/src/app_config.cpp index 35296d8..f06e085 100644 --- a/src/app_config.cpp +++ b/src/app_config.cpp @@ -31,6 +31,8 @@ namespace duck { namespace { + constexpr const std::size_t g_min_update_timeout = 60; + constexpr const char g_db_path_sect[] = "system"; constexpr const char g_db_path[] = "db_path"; @@ -90,11 +92,6 @@ namespace { ); } - double to_double (std::string_view val) { - const auto seconds = dhandy::int_conv(val); - return static_cast(seconds); - } - std::string whole_ini() { std::ifstream input(g_config_file_path); input >> std::noskipws; @@ -188,24 +185,24 @@ bool AppConfig::store_raw_json() const { return to_bool(val); } -double AppConfig::items_timeout() const { +std::size_t AppConfig::items_timeout() const { std::string_view val = value_ifp(m_ini, g_items_time_sect, g_items_time, g_items_time_def, false); - return to_double(val); + return std::max(dhandy::int_conv(val), g_min_update_timeout); } -double AppConfig::icons_timeout() const { +std::size_t AppConfig::icons_timeout() const { std::string_view val = value_ifp(m_ini, g_icons_time_sect, g_icons_time, g_icons_time_def, false); - return to_double(val); + return std::max(dhandy::int_conv(val), g_min_update_timeout); } -double AppConfig::shops_timeout() const { +std::size_t AppConfig::shops_timeout() const { std::string_view val = value_ifp(m_ini, g_shops_time_sect, g_shops_time, g_shops_time_def, false); - return to_double(val); + return std::max(dhandy::int_conv(val), g_min_update_timeout); } -double AppConfig::creators_timeout() const { +std::size_t AppConfig::creators_timeout() const { std::string_view val = value_ifp(m_ini, g_creators_time_sect, g_creators_time, g_creators_time_def, false); - return to_double(val); + return std::max(dhandy::int_conv(val), g_min_update_timeout); } } //namespace duck diff --git a/src/app_config.hpp b/src/app_config.hpp index 726f083..207cd0a 100644 --- a/src/app_config.hpp +++ b/src/app_config.hpp @@ -35,10 +35,10 @@ public: std::string_view backend() const; bool store_raw_json() const; - double items_timeout() const; - double icons_timeout() const; - double shops_timeout() const; - double creators_timeout() const; + std::size_t items_timeout() const; + std::size_t icons_timeout() const; + std::size_t shops_timeout() const; + std::size_t creators_timeout() const; private: kamokan::IniFile m_ini; diff --git a/src/evloop.cpp b/src/evloop.cpp index 0c2df0b..e918810 100644 --- a/src/evloop.cpp +++ b/src/evloop.cpp @@ -74,10 +74,10 @@ void test(oro::Api* api, oro::OriginsDB* db, const AppConfig& app_conf) { auto sig_int = worker.make_event(&worker); const bool rj = app_conf.store_raw_json(); - const double w1 = app_conf.items_timeout(); - const double w2 = app_conf.icons_timeout(); - const double w3 = app_conf.shops_timeout(); - const double w4 = app_conf.creators_timeout(); + const double w1 = static_cast(app_conf.items_timeout()); + const double w2 = static_cast(app_conf.icons_timeout()); + const double w3 = static_cast(app_conf.shops_timeout()); + const double w4 = static_cast(app_conf.creators_timeout()); auto timer_items = worker.make_event(TSet{w1, ed, rj}, &pool, api, db); auto timer_icons = worker.make_event(TSet{w2, ed, rj}, &pool, api, db);