Skip to content

Commit 77ac756

Browse files
authored
Merge pull request #73 from giulcioffi/fix_repeated_status_issue
Fix issue due to repeated status()/connected() call
2 parents fc6bd42 + e303e39 commit 77ac756

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arduino/libraries/WiFi/src/WiFiClient.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ int WiFiClient::available()
105105

106106
int result = 0;
107107

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

154+
//This function tries to receive data from the network and can return an error if the connection when down.
153155
if (lwip_recv_r(_socket, &b, sizeof(b), MSG_PEEK | MSG_DONTWAIT) <= 0) {
154156
if (errno != EWOULDBLOCK) {
155157
lwip_close_r(_socket);
@@ -177,7 +179,10 @@ void WiFiClient::stop()
177179
uint8_t WiFiClient::connected()
178180
{
179181
if (_socket != -1) {
180-
peek();
182+
//Check if there are already available data and, if not, try to read new ones from the network.
183+
if (!available()) {
184+
peek();
185+
}
181186
}
182187

183188
return (_socket != -1);

0 commit comments

Comments
 (0)