Skip to content

Alternative Improve _uploadReadByte #2656

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

Merged
merged 12 commits into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review comments; move impl to cpp file for getTimeout, and re…
…move local variable for currentMillis
  • Loading branch information
vicatcu committed Apr 11, 2019
commit d5c501f7687be64e5995189eb0be44c1fb53c7d8
3 changes: 3 additions & 0 deletions cores/esp32/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
{
_timeout = timeout;
}
unsigned long Stream::getTimeout(void) {
return _timeout;
}

// find returns true if the target string is found
bool Stream::find(const char *target)
Expand Down
5 changes: 1 addition & 4 deletions cores/esp32/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ class Stream: public Print
// parsing methods

void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
unsigned long getTimeout(void)
{
return _timeout;
}
unsigned long getTimeout(void);
bool find(const char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target)
{
Expand Down
4 changes: 1 addition & 3 deletions libraries/WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,12 @@ int WebServer::_uploadReadByte(WiFiClient& client){
// keep trying until you either read a valid byte or timeout
unsigned long startMillis = millis();
long timeoutIntervalMillis = client.getTimeout();
unsigned long currentMillis = startMillis;
boolean timedOut = false;
for(;;) {
// loosely modeled after blinkWithoutDelay pattern
while(!timedOut && !client.available() && client.connected()){
delay(2);
currentMillis = millis();
timedOut = currentMillis - startMillis >= timeoutIntervalMillis;
timedOut = ((unsigned long) millis()) - startMillis >= timeoutIntervalMillis;
}

res = client.read();
Expand Down