-
-
Notifications
You must be signed in to change notification settings - Fork 86
Fix 10 second delay in WiFiClient read methods when no data is available to read #458
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
Fix 10 second delay in WiFiClient read methods when no data is available to read #458
Conversation
…of that data is zero
libraries/WiFiS3/src/Modem.cpp
Outdated
if (sized_read_size == 0) { | ||
state = at_parse_state_t::Res; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the state transition at line 297 and keep the state change next to each other. This will improve the readability.
if (sized_read_size == 0) { | |
state = at_parse_state_t::Res; | |
} | |
if (sized_read_size != 0) { | |
state = at_parse_state_t::Sized; | |
} else { | |
state = at_parse_state_t::Res; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the good suggestion - I have added another commit to address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgcookson Thanks for your contribution, it is really appreciated!
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