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

WiFiClient improperly treats zero data available for read as an error #4435

Closed
MHotchin opened this issue Oct 22, 2020 · 4 comments
Closed

Comments

@MHotchin
Copy link
Contributor

In "arduino-esp32/libraries/WiFi/src/WiFiClient.cpp".

If the client has run out of data that has been received, it will return an error, instead of returning 0 (indicating no data available right now).

Starting line 106:

    int read(uint8_t * dst, size_t len){
        if(!dst || !len || (_pos == _fill && !fillBuffer())){
            return -1;

Change to:

    int read(uint8_t * dst, size_t len){
        if(!dst || !len || (_pos == _fill && !fillBuffer())){
            return _failed ? -1: 0;
@MHotchin
Copy link
Contributor Author

This appears to be the cause of #4390 as well.

@MHotchin
Copy link
Contributor Author

Add to fix - function 'read() needs to handle the zero data available case as well. Found by using readBytes(), which calls the single byte version of read().

int WiFiClient::read()
{
    uint8_t data = 0;
    int res = read(&data, 1);
    if(res < 0) {
        return res;
    }
    if (res == 0) {
        return -1;
    }
    return data;
}

@MarkusAD
Copy link
Contributor

@MHotchin you should submit your changes as a pull request so that they can be reviewed and merged into the current code base.

MHotchin added a commit to MHotchin/arduino-esp32 that referenced this issue Oct 27, 2020
@MHotchin
Copy link
Contributor Author

PR #4448 submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants