File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 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) {
323323size_t UpdateClass::writeStream (Stream &data) {
324324 size_t written = 0 ;
325325 size_t toRead = 0 ;
326+ int timeout_failures = 0 ;
327+
326328 if (hasError () || !isRunning ())
327329 return 0 ;
328330
@@ -344,15 +346,24 @@ size_t UpdateClass::writeStream(Stream &data) {
344346 bytesToRead = remaining ();
345347 }
346348
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 );
354364 }
355365 }
366+
356367 if (_ledPin != -1 ) {
357368 digitalWrite (_ledPin, !_ledOn); // Switch LED off
358369 }
You can’t perform that action at this time.
0 commit comments