diff options
author | dec05eba <0xdec05eba@gmail.com> | 2018-04-29 14:45:53 +0200 |
---|---|---|
committer | dec05eba <0xdec05eba@gmail.com> | 2018-04-29 14:46:00 +0200 |
commit | 54de8e3b0b353b8c62b566dabb7b082a1cdd371e (patch) | |
tree | e0fdf83b79ee9547214f209b7986cc51394b728c | |
parent | 9519d5fc682f83b2a4d78fe8f66b169a8c9314eb (diff) |
Fail if ntp fails
-rw-r--r-- | src/Database.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Database.cpp b/src/Database.cpp index cf72c6a..f2d0fe1 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -121,7 +121,8 @@ namespace odhtdb ntp::NtpClient ntpClient("pool.ntp.org"); while(databaseCount > 0) { - for(int i = 0; i < ntpFetchTimestampRetries; ++i) + int fetchRetryCounter = 0; + while(fetchRetryCounter < ntpFetchTimestampRetries) { try { @@ -132,11 +133,15 @@ namespace odhtdb } catch(ntp::NtpClientException &e) { - Log::warn("Failed to sync clock with ntp server, reason: %s. Try #%d", e.what(), i); + Log::warn("Failed to sync clock with ntp server, reason: %s. Try #%d", e.what(), fetchRetryCounter); this_thread::sleep_for(500ms); } + ++fetchRetryCounter; } - // TODO: Also use timestamp fraction (milliseconds) + + if(fetchRetryCounter == ntpFetchTimestampRetries) + throw ntp::NtpClientException("Failed to retrieve ntp timestamp after several retries"); + this_thread::sleep_for(60s); } timestampSynced = false; |