Skip to content

Commit

Permalink
Add a configurable NTP timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightkingale committed Jun 7, 2024
1 parent 35039db commit 0181e2a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/cfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace cfg {
extern const char* server;
extern const char* sync;
extern const char* threads;
extern const char* timeout;
extern const char* tolerance;
extern const char* tz_service;
extern const char* utc_offset;
Expand All @@ -29,6 +30,7 @@ namespace cfg {
extern const char* server;
extern const char* sync;
extern const char* threads;
extern const char* timeout;
extern const char* tolerance;
extern const char* tz_service;
extern const char* utc_offset;
Expand All @@ -41,6 +43,7 @@ namespace cfg {
extern const std::string server;
extern const bool sync;
extern const int threads;
extern const std::chrono::seconds timeout;
extern const std::chrono::milliseconds tolerance;
extern const int tz_service;
}
Expand All @@ -52,6 +55,7 @@ namespace cfg {
extern std::string server;
extern bool sync;
extern int threads;
extern std::chrono::seconds timeout;
extern std::chrono::milliseconds tolerance;
extern int tz_service;
extern std::chrono::minutes utc_offset;
Expand Down
5 changes: 5 additions & 0 deletions source/cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace cfg {
const char* server = "server";
const char* sync = "sync";
const char* threads = "threads";
const char* timeout = "timeout";
const char* tolerance = "tolerance";
const char* tz_service = "tz_service";
const char* utc_offset = "utc_offset";
Expand All @@ -39,6 +40,7 @@ namespace cfg {
const char* server = "NTP Servers";
const char* sync = "Syncing Enabled";
const char* threads = "Background Threads";
const char* timeout = "Timeout";
const char* tolerance = "Tolerance";
const char* tz_service = "Detect Time Zone (press " NIN_GLYPH_BTN_A ")";
const char* utc_offset = "Time Offset (UTC)";
Expand All @@ -52,6 +54,7 @@ namespace cfg {
const std::string server = "pool.ntp.org";
const bool sync = false;
const int threads = 4;
const seconds timeout = 5s;
const milliseconds tolerance = 500ms;
const int tz_service = 0;
}
Expand All @@ -63,6 +66,7 @@ namespace cfg {
std::string server = defaults::server;
bool sync = defaults::sync;
int threads = defaults::threads;
seconds timeout = defaults::timeout;
milliseconds tolerance = defaults::tolerance;
int tz_service = defaults::tz_service;
minutes utc_offset = 0min;
Expand Down Expand Up @@ -91,6 +95,7 @@ namespace cfg {
load_or_init(key::server, server);
load_or_init(key::sync, sync);
load_or_init(key::threads, threads);
load_or_init(key::timeout, timeout);
load_or_init(key::tolerance, tolerance);
load_or_init(key::tz_service, tz_service);
load_or_init(key::utc_offset, utc_offset);
Expand Down
6 changes: 6 additions & 0 deletions source/config_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ make_config_screen()
cfg::defaults::msg_duration,
1s, 30s, 5s));

cat.add(seconds_item::create(cfg::key::timeout,
cfg::label::timeout,
cfg::timeout,
cfg::defaults::timeout,
1s, 10s, 5s));

cat.add(milliseconds_item::create(cfg::key::tolerance,
cfg::label::tolerance,
cfg::tolerance,
Expand Down
2 changes: 1 addition & 1 deletion source/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace core {
unsigned poll_attempts = 0;
const unsigned max_poll_attempts = 4;
try_again_poll:
auto readable_status = sock.try_is_readable(4s);
auto readable_status = sock.try_is_readable(cfg::timeout);
if (!readable_status) {
// Wii U OS can only handle 16 concurrent select()/poll() calls,
// so we may need to try again later.
Expand Down

0 comments on commit 0181e2a

Please sign in to comment.