From bb0a194bb78592cff3e198b661bf36b2d79ee833 Mon Sep 17 00:00:00 2001 From: Mark D Date: Tue, 21 Jan 2020 05:36:03 -0500 Subject: [PATCH] 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. --- libraries/WiFi/src/WiFiClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index a92dadb2..e422b636 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -495,8 +495,8 @@ uint8_t WiFiClient::connected() int res = recv(fd(), &dummy, 0, MSG_DONTWAIT); // avoid unused var warning by gcc (void)res; - // recv only sets errno if res is -1 - if (res < 0){ + // recv only sets errno if res is <= 0 + if (res <= 0){ switch (errno) { case EWOULDBLOCK: case ENOENT: //caused by vfs