Skip to content

Commit 89351e3

Browse files
Vigeantme-no-dev
authored andcommitted
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.
1 parent 86de90f commit 89351e3

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

Diff for: libraries/WiFi/src/WiFiClient.cpp

+22-17
Original file line numberDiff line numberDiff line change
@@ -495,23 +495,28 @@ uint8_t WiFiClient::connected()
495495
int res = recv(fd(), &dummy, 0, MSG_DONTWAIT);
496496
// avoid unused var warning by gcc
497497
(void)res;
498-
switch (errno) {
499-
case EWOULDBLOCK:
500-
case ENOENT: //caused by vfs
501-
_connected = true;
502-
break;
503-
case ENOTCONN:
504-
case EPIPE:
505-
case ECONNRESET:
506-
case ECONNREFUSED:
507-
case ECONNABORTED:
508-
_connected = false;
509-
log_d("Disconnected: RES: %d, ERR: %d", res, errno);
510-
break;
511-
default:
512-
log_i("Unexpected: RES: %d, ERR: %d", res, errno);
513-
_connected = true;
514-
break;
498+
// recv only sets errno if res is -1
499+
if (res < 0){
500+
switch (errno) {
501+
case EWOULDBLOCK:
502+
case ENOENT: //caused by vfs
503+
_connected = true;
504+
break;
505+
case ENOTCONN:
506+
case EPIPE:
507+
case ECONNRESET:
508+
case ECONNREFUSED:
509+
case ECONNABORTED:
510+
_connected = false;
511+
log_d("Disconnected: RES: %d, ERR: %d", res, errno);
512+
break;
513+
default:
514+
log_i("Unexpected: RES: %d, ERR: %d", res, errno);
515+
_connected = true;
516+
break;
517+
}
518+
} else {
519+
_connected = true;
515520
}
516521
}
517522
return _connected;

0 commit comments

Comments
 (0)