Skip to content

Commit 0328fde

Browse files
author
adrionics
authored
Merge pull request #1 from adrionics/adrionics-patch-updater-stream-timeout
Update Updater.cpp
2 parents 3835991 + 07e30d6 commit 0328fde

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

cores/esp8266/Updater.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ bool UpdaterClass::_verifyEnd() {
433433
return false;
434434
}
435435

436-
size_t UpdaterClass::writeStream(Stream &data) {
436+
size_t UpdaterClass::writeStream(Stream &data, uint16_t streamTimeout) {
437437
size_t written = 0;
438438
size_t toRead = 0;
439439
if(hasError() || !isRunning())
@@ -446,6 +446,7 @@ size_t UpdaterClass::writeStream(Stream &data) {
446446
_reset();
447447
return 0;
448448
}
449+
unsigned long timeout = millis();
449450
if (_progress_callback) {
450451
_progress_callback(0, _size);
451452
}
@@ -463,14 +464,15 @@ size_t UpdaterClass::writeStream(Stream &data) {
463464
}
464465
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
465466
if(toRead == 0) { //Timeout
466-
delay(100);
467-
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
468-
if(toRead == 0) { //Timeout
469-
_currentAddress = (_startAddress + _size);
470-
_setError(UPDATE_ERROR_STREAM);
471-
_reset();
472-
return written;
473-
}
467+
if (millis() - timeout > streamTimeout) {
468+
_currentAddress = (_startAddress + _size);
469+
_setError(UPDATE_ERROR_STREAM);
470+
_reset();
471+
return written;
472+
}
473+
delay(100);
474+
} else {
475+
timeout = millis();
474476
}
475477
if(_ledPin != -1) {
476478
digitalWrite(_ledPin, !_ledOn); // Switch LED off

0 commit comments

Comments
 (0)