From 2d4880cbfeedfba37d7f69dbddea2bff0ae80bab Mon Sep 17 00:00:00 2001 From: Daniel Mohr Date: Wed, 2 Aug 2023 20:27:50 +0200 Subject: [PATCH] fixes infinite loop in force_update (close #6) --- README.md | 2 +- library.properties | 2 +- src/precise_sntp.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4c76cdb..32a7619 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ --- author: Daniel Mohr -date: 2023-01-18 +date: 2023-08-02 url: https://github.com/ug-cp/precise_sntp license: BSD 3-Clause License --- diff --git a/library.properties b/library.properties index b2df01d..cbf17e7 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=precise_sntp -version=0.2.4 +version=0.2.5 author=Daniel Mohr maintainer=Daniel Mohr sentence=This library is an implementation of the Simple Network Time Protocol (SNTPv4) for the arduino platform providing sub-second precision. diff --git a/src/precise_sntp.cpp b/src/precise_sntp.cpp index cd4fcd9..a282e52 100644 --- a/src/precise_sntp.cpp +++ b/src/precise_sntp.cpp @@ -1,6 +1,6 @@ /* Author: Daniel Mohr - Date: 2022-12-15 + Date: 2023-08-02 For more information look at the README.md. @@ -196,7 +196,10 @@ uint8_t precise_sntp::force_update(bool use_transmit_timestamp) { unsigned long start_waiting = millis(); int packetSize; while (((packetSize = _udp->parsePacket()) != NTP_PACKET_SIZE) && - (start_waiting + 1000)) { + (millis() - start_waiting < 1000)) { + // Wait until all data received. But wait maximal 1000 milliseconds. + // If millis overflows it is less 1000 milliseconds and + // otherwise it waits up to 1000 milliseconds for an answer. } if (packetSize != NTP_PACKET_SIZE) { #ifdef PRECISE_SNTP_DEBUG