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.stop doesn't discard any remaining data in the read buffer [imported] #1030

Closed
cmaglie opened this issue Nov 15, 2012 · 1 comment
Assignees
Labels
Library: Wifi The Wifi Arduino library

Comments

@cmaglie
Copy link
Member

cmaglie commented Nov 15, 2012

This is Issue 1030 moved from a Google Code project.
Added by 2012-09-03T18:31:07.000Z by adrian.m...@gmail.com.
Please review that bug for more context and additional comments, but update this bug.

Original labels: Type-Defect, Priority-Medium

Original description

If you close a connection before you've read all the data left in the read buffer, that data seems to stay around until the next time that socket is used, and gets incorrectly delivered as data having been read in the new connection.

You can see it happening by trying the WiFiDatastreamUpload example in the Cosm library https://github.com/amcewen/Cosm-Arduino - the first upload will succeed (or if you've not set the API key or feed id correctly, fail with a -40x error code) and subsequent attempts will fail with an error of -4 (which the HttpClient library returns if it doesn't understand the response - because it's being fed data from the previous request)

Adding a call to flush() during stop() seems to fix the problem.

void WiFiClient::stop() {

if (_sock == 255)
return;

  • flush();
    ServerDrv::stopClient(_sock);

    unsigned long start = millis();

    // wait a second for the connection to close
    while (status() != CLOSED && millis() - start < 1000)
    delay(1);
    _sock = 255;
    }

@agdl
Copy link
Member

agdl commented Jul 12, 2016

This issue was moved to arduino-libraries/WiFi#20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Library: Wifi The Wifi Arduino library
Projects
None yet
Development

No branches or pull requests

3 participants