File tree 1 file changed +18
-7
lines changed
1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -323,6 +323,8 @@ size_t UpdateClass::write(uint8_t *data, size_t len) {
323
323
size_t UpdateClass::writeStream (Stream &data) {
324
324
size_t written = 0 ;
325
325
size_t toRead = 0 ;
326
+ int timeout_failures = 0 ;
327
+
326
328
if (hasError () || !isRunning ())
327
329
return 0 ;
328
330
@@ -344,15 +346,24 @@ size_t UpdateClass::writeStream(Stream &data) {
344
346
bytesToRead = remaining ();
345
347
}
346
348
347
- toRead = data.readBytes (_buffer + _bufferLen, bytesToRead);
348
- if (toRead == 0 ) { // Timeout
349
- delay (100 );
350
- toRead = data.readBytes (_buffer + _bufferLen, bytesToRead);
351
- if (toRead == 0 ) { // Timeout
352
- _abort (UPDATE_ERROR_STREAM);
353
- return written;
349
+ /*
350
+ Init read&timeout counters and try to read, if read failed, increase counter,
351
+ wait 100ms and try to read again. If counter > 300 (30 sec), give up/abort
352
+ */
353
+ toRead = 0 ;
354
+ timeout_failures = 0 ;
355
+ while (!toRead) {
356
+ toRead = data.readBytes (_buffer + _bufferLen, bytesToRead);
357
+ if (toRead == 0 ) {
358
+ timeout_failures++;
359
+ if (timeout_failures >= 300 ) {
360
+ _abort (UPDATE_ERROR_STREAM);
361
+ return written;
362
+ }
363
+ delay (100 );
354
364
}
355
365
}
366
+
356
367
if (_ledPin != -1 ) {
357
368
digitalWrite (_ledPin, !_ledOn); // Switch LED off
358
369
}
You can’t perform that action at this time.
0 commit comments