From d46f2063e04ee49c631e8966029affd8dd1fa5e4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 29 Apr 2018 14:45:53 +0200 Subject: Fail if ntp fails --- src/Database.cpp | 11 ++++++++--- 1 file 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; -- cgit v1.2.3