Skip to content

Commit bb0a194

Browse files
markyadme-no-dev
authored andcommitted
fix WiFiClient.connected() (#3654)
WiFiClient.connected() was hanging thinking there was still a connection when the remote had already closed. The one-liner in this patch addresses recv() returning 0 and errno==128. I couldn't find the corresponding errno for 128 but its caught by the case statement which includes EPIPE, ENOTCONN, ECONNRESET and ECONNABORTED so I assume its one of those. Broken pipe maybe? ```c [D][WiFiClient.cpp:511] connected(): Disconnected: RES: 0, ERR: 128 ``` EDIT: added comment to reflect that recv() can set errno when it returns 0.
1 parent ed59ae6 commit bb0a194

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,8 @@ uint8_t WiFiClient::connected()
495495
int res = recv(fd(), &dummy, 0, MSG_DONTWAIT);
496496
// avoid unused var warning by gcc
497497
(void)res;
498-
// recv only sets errno if res is -1
499-
if (res < 0){
498+
// recv only sets errno if res is <= 0
499+
if (res <= 0){
500500
switch (errno) {
501501
case EWOULDBLOCK:
502502
case ENOENT: //caused by vfs

0 commit comments

Comments
 (0)