File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
arduino/libraries/WiFi/src Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff 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()
177179uint8_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 );
You can’t perform that action at this time.
0 commit comments