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

Fix issue due to repeated status()/connected() call #73

Merged
merged 2 commits into from
Jul 29, 2021
Merged
Changes from all commits
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
7 changes: 6 additions & 1 deletion arduino/libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ int WiFiClient::available()

int result = 0;

//This function returns the number of bytes of pending data already received in the socket’s network.
if (lwip_ioctl_r(_socket, FIONREAD, &result) < 0) {
lwip_close_r(_socket);
_socket = -1;
Expand Down Expand Up @@ -150,6 +151,7 @@ int WiFiClient::peek()
{
uint8_t b;

//This function tries to receive data from the network and can return an error if the connection when down.
if (lwip_recv_r(_socket, &b, sizeof(b), MSG_PEEK | MSG_DONTWAIT) <= 0) {
if (errno != EWOULDBLOCK) {
lwip_close_r(_socket);
Expand Down Expand Up @@ -177,7 +179,10 @@ void WiFiClient::stop()
uint8_t WiFiClient::connected()
{
if (_socket != -1) {
peek();
//Check if there are already available data and, if not, try to read new ones from the network.
if (!available()) {
peek();
}
}

return (_socket != -1);
Expand Down