Skip to content

Commit

Permalink
Replace _uploadReadByte() in WebServer/Parsing.cpp with ESP8266 imple…
Browse files Browse the repository at this point in the history
…mentation.
  • Loading branch information
everslick authored Jan 26, 2024
1 parent bd941e3 commit 16f7d34
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions libraries/WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,42 +309,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
_currentUpload->buf[_currentUpload->currentSize++] = b;
}

int WebServer::_uploadReadByte(WiFiClient& client){
int WebServer::_uploadReadByte(WiFiClient& client) {
int res = client.read();
if(res < 0) {
// keep trying until you either read a valid byte or timeout
unsigned long startMillis = millis();
long timeoutIntervalMillis = client.getTimeout();
boolean timedOut = false;
for(;;) {
if (!client.connected()) return -1;
// loosely modeled after blinkWithoutDelay pattern
while(!timedOut && !client.available() && client.connected()){
delay(2);
timedOut = millis() - startMillis >= timeoutIntervalMillis;
}

res = client.read();
if(res >= 0) {
return res; // exit on a valid read
}
// NOTE: it is possible to get here and have all of the following
// assertions hold true
//
// -- client.available() > 0
// -- client.connected == true
// -- res == -1
//
// a simple retry strategy overcomes this which is to say the
// assertion is not permanent, but the reason that this works
// is elusive, and possibly indicative of a more subtle underlying
// issue

timedOut = millis() - startMillis >= timeoutIntervalMillis;
if(timedOut) {
return res; // exit on a timeout
}
}
if (res < 0) {
while(!client.available() && client.connected())
delay(2);

res = client.read();
}

return res;
Expand Down

0 comments on commit 16f7d34

Please sign in to comment.