Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Improve _uploadReadByte #2656

Merged
merged 12 commits into from
Apr 12, 2019
37 changes: 32 additions & 5 deletions libraries/WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,39 @@ void WebServer::_uploadWriteByte(uint8_t b){

int WebServer::_uploadReadByte(WiFiClient& client){
int res = client.read();
if(res == -1){
while(!client.available() && client.connected())
delay(2);
res = client.read();
if(res < 0) {
// keep trying until you either read a valid byte or timeout
const unsigned long startMillis = millis();
vicatcu marked this conversation as resolved.
Show resolved Hide resolved
const long timeoutIntervalMillis = HTTP_MAX_POST_WAIT;
unsigned long currentMillis = startMillis;
for(;;) {
// loosely modeled after blinkWithoutDelay pattern
while(!client.available() && client.connected()){
delay(2);
}

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 ellusive, and possibly indicative of a more subtle underlying
// issue

currentMillis = millis();
if(currentMillis - startMillis >= timeoutIntervalMillis) {
return -1; // exit on a timeout
}
}
}
return res;
vicatcu marked this conversation as resolved.
Show resolved Hide resolved
}

bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
Expand Down