aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-04-29 14:45:53 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitd46f2063e04ee49c631e8966029affd8dd1fa5e4 (patch)
treeae1d349604f5071cfa698faae527f7f4afee00c0 /src
parentdd0c526c726af7e20de9c82c6c68056f093fc7d1 (diff)
Fail if ntp fails
Diffstat (limited to 'src')
-rw-r--r--src/Database.cpp11
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;