Fix 10 second delay in WiFiClient read methods when no data is available to read #458
+6
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Summary
Prior to v1.3.0 of core, invoking either
WiFiClient::read()
orWiFiClient::read(uint8_t *buf, size_t size)
when there was no data available to read would result in those methods returning immediately with expected return codes (-1 for the former and 0 for the latter).As of v1.3.0, both 'read' methods now unexpectedly delay for 10 seconds in the 'no data available' scenario before returning the expected return codes. This change in behavior was introduced via PR #349.
Proposed Fix
This PR contains a proposed fix that allows the state machine used to read (WiFi) modem responses to immediately transition to the next state when the indicated data length in the response is zero, instead of getting stuck in the 'read data' state.
Research Notes
Example affected code excerpts with results
Code invoking WiFiClient::read()
Results when run under core 1.2.2
Results when run under core 1.4.1
Code invoking WiFiClient::read(uint8_t *buf, size_t size)
Results when run under core 1.2.2
Results when run under core 1.4.1
Modem.cpp debug output before and after proposed fix
Enabling modem debug output using
modem.debug(Serial, 3)
yields the following results:Results when run under core 1.4.1 prior to this fix
Results when run under core 1.4.1 after this fix