Update WiFiClient.cpp (#3608)

fixed the connected() function so that it only checks errno if recv returns a value of -1.

"in the even of an error, errno is set to indicate the error" --manpage

This fixes the ESP32 Webserver when dealing with a modern webserver with a slow SD card.
This commit is contained in:
Guil-T 2020-01-20 09:08:17 -05:00 committed by Me No Dev
parent 86de90fe24
commit 89351e3ade

View File

@ -495,23 +495,28 @@ uint8_t WiFiClient::connected()
int res = recv(fd(), &dummy, 0, MSG_DONTWAIT); int res = recv(fd(), &dummy, 0, MSG_DONTWAIT);
// avoid unused var warning by gcc // avoid unused var warning by gcc
(void)res; (void)res;
switch (errno) { // recv only sets errno if res is -1
case EWOULDBLOCK: if (res < 0){
case ENOENT: //caused by vfs switch (errno) {
_connected = true; case EWOULDBLOCK:
break; case ENOENT: //caused by vfs
case ENOTCONN: _connected = true;
case EPIPE: break;
case ECONNRESET: case ENOTCONN:
case ECONNREFUSED: case EPIPE:
case ECONNABORTED: case ECONNRESET:
_connected = false; case ECONNREFUSED:
log_d("Disconnected: RES: %d, ERR: %d", res, errno); case ECONNABORTED:
break; _connected = false;
default: log_d("Disconnected: RES: %d, ERR: %d", res, errno);
log_i("Unexpected: RES: %d, ERR: %d", res, errno); break;
_connected = true; default:
break; log_i("Unexpected: RES: %d, ERR: %d", res, errno);
_connected = true;
break;
}
} else {
_connected = true;
} }
} }
return _connected; return _connected;