@@ -90,7 +90,8 @@ bool NTPClient::forceUpdate() {
90
90
while (this ->_udp ->parsePacket () != 0 )
91
91
this ->_udp ->flush ();
92
92
93
- this ->sendNTPPacket ();
93
+ if (!this ->sendNTPPacket ())
94
+ return false ;
94
95
95
96
// Wait till data is there or timeout...
96
97
byte timeout = 0 ;
@@ -104,7 +105,8 @@ bool NTPClient::forceUpdate() {
104
105
105
106
this ->_lastUpdate = millis () - (10 * (timeout + 1 )); // Account for delay in reading the time
106
107
107
- this ->_udp ->read (this ->_packetBuffer , NTP_PACKET_SIZE);
108
+ if (this ->_udp ->read (this ->_packetBuffer , NTP_PACKET_SIZE) != NTP_PACKET_SIZE)
109
+ return false ;
108
110
109
111
unsigned long highWord = word (this ->_packetBuffer [40 ], this ->_packetBuffer [41 ]);
110
112
unsigned long lowWord = word (this ->_packetBuffer [42 ], this ->_packetBuffer [43 ]);
@@ -181,7 +183,7 @@ void NTPClient::setPoolServerName(const char* poolServerName) {
181
183
this ->_poolServerName = poolServerName;
182
184
}
183
185
184
- void NTPClient::sendNTPPacket () {
186
+ bool NTPClient::sendNTPPacket () {
185
187
// set all bytes in the buffer to 0
186
188
memset (this ->_packetBuffer , 0 , NTP_PACKET_SIZE);
187
189
// Initialize values needed to form NTP request
@@ -197,13 +199,20 @@ void NTPClient::sendNTPPacket() {
197
199
198
200
// all NTP fields have been given values, now
199
201
// you can send a packet requesting a timestamp:
202
+
203
+ bool success = false ;
200
204
if (this ->_poolServerName ) {
201
- this ->_udp ->beginPacket (this ->_poolServerName , 123 );
205
+ success = this ->_udp ->beginPacket (this ->_poolServerName , 123 );
202
206
} else {
203
- this ->_udp ->beginPacket (this ->_poolServerIP , 123 );
207
+ success = this ->_udp ->beginPacket (this ->_poolServerIP , 123 );
204
208
}
205
- this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE);
206
- this ->_udp ->endPacket ();
209
+
210
+ if (success)
211
+ if (this ->_udp ->write (this ->_packetBuffer , NTP_PACKET_SIZE) == NTP_PACKET_SIZE)
212
+ if (this ->_udp ->endPacket ())
213
+ return true ;
214
+
215
+ return false ;
207
216
}
208
217
209
218
void NTPClient::setRandomPort (unsigned int minValue, unsigned int maxValue) {
0 commit comments