Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4b008e

Browse filesBrowse files
authored
Handle stream timeouts properly, for slow HTTP/HTTPS links (espressif#3752)
This patch fixes update timeouts (error espressif#6) on slow HTTP/HTTPS links.
1 parent 76afaf2 commit e4b008e
Copy full SHA for e4b008e

File tree

Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-7
lines changed

‎libraries/Update/src/Updater.cpp

Copy file name to clipboardExpand all lines: libraries/Update/src/Updater.cpp
+18-7Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ size_t UpdateClass::write(uint8_t *data, size_t len) {
323323
size_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
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.