Skip to content

Commit 0181e2a

Browse files
committed
Add a configurable NTP timeout
1 parent 35039db commit 0181e2a

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

include/cfg.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace cfg {
1616
extern const char* server;
1717
extern const char* sync;
1818
extern const char* threads;
19+
extern const char* timeout;
1920
extern const char* tolerance;
2021
extern const char* tz_service;
2122
extern const char* utc_offset;
@@ -29,6 +30,7 @@ namespace cfg {
2930
extern const char* server;
3031
extern const char* sync;
3132
extern const char* threads;
33+
extern const char* timeout;
3234
extern const char* tolerance;
3335
extern const char* tz_service;
3436
extern const char* utc_offset;
@@ -41,6 +43,7 @@ namespace cfg {
4143
extern const std::string server;
4244
extern const bool sync;
4345
extern const int threads;
46+
extern const std::chrono::seconds timeout;
4447
extern const std::chrono::milliseconds tolerance;
4548
extern const int tz_service;
4649
}
@@ -52,6 +55,7 @@ namespace cfg {
5255
extern std::string server;
5356
extern bool sync;
5457
extern int threads;
58+
extern std::chrono::seconds timeout;
5559
extern std::chrono::milliseconds tolerance;
5660
extern int tz_service;
5761
extern std::chrono::minutes utc_offset;

source/cfg.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace cfg {
2626
const char* server = "server";
2727
const char* sync = "sync";
2828
const char* threads = "threads";
29+
const char* timeout = "timeout";
2930
const char* tolerance = "tolerance";
3031
const char* tz_service = "tz_service";
3132
const char* utc_offset = "utc_offset";
@@ -39,6 +40,7 @@ namespace cfg {
3940
const char* server = "NTP Servers";
4041
const char* sync = "Syncing Enabled";
4142
const char* threads = "Background Threads";
43+
const char* timeout = "Timeout";
4244
const char* tolerance = "Tolerance";
4345
const char* tz_service = "Detect Time Zone (press " NIN_GLYPH_BTN_A ")";
4446
const char* utc_offset = "Time Offset (UTC)";
@@ -52,6 +54,7 @@ namespace cfg {
5254
const std::string server = "pool.ntp.org";
5355
const bool sync = false;
5456
const int threads = 4;
57+
const seconds timeout = 5s;
5558
const milliseconds tolerance = 500ms;
5659
const int tz_service = 0;
5760
}
@@ -63,6 +66,7 @@ namespace cfg {
6366
std::string server = defaults::server;
6467
bool sync = defaults::sync;
6568
int threads = defaults::threads;
69+
seconds timeout = defaults::timeout;
6670
milliseconds tolerance = defaults::tolerance;
6771
int tz_service = defaults::tz_service;
6872
minutes utc_offset = 0min;
@@ -91,6 +95,7 @@ namespace cfg {
9195
load_or_init(key::server, server);
9296
load_or_init(key::sync, sync);
9397
load_or_init(key::threads, threads);
98+
load_or_init(key::timeout, timeout);
9499
load_or_init(key::tolerance, tolerance);
95100
load_or_init(key::tz_service, tz_service);
96101
load_or_init(key::utc_offset, utc_offset);

source/config_screen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ make_config_screen()
6363
cfg::defaults::msg_duration,
6464
1s, 30s, 5s));
6565

66+
cat.add(seconds_item::create(cfg::key::timeout,
67+
cfg::label::timeout,
68+
cfg::timeout,
69+
cfg::defaults::timeout,
70+
1s, 10s, 5s));
71+
6672
cat.add(milliseconds_item::create(cfg::key::tolerance,
6773
cfg::label::tolerance,
6874
cfg::tolerance,

source/core.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ namespace core {
121121
unsigned poll_attempts = 0;
122122
const unsigned max_poll_attempts = 4;
123123
try_again_poll:
124-
auto readable_status = sock.try_is_readable(4s);
124+
auto readable_status = sock.try_is_readable(cfg::timeout);
125125
if (!readable_status) {
126126
// Wii U OS can only handle 16 concurrent select()/poll() calls,
127127
// so we may need to try again later.

0 commit comments

Comments
 (0)