From fd36085b1d244d022365ab73a95f2bb0ffe0c611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Thu, 27 Oct 2022 11:48:23 -0500 Subject: [PATCH 1/2] Fix unused-variable warnings that are flagged as errors in some Arduino IDE setups --- src/AsyncTCP.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index d39a8aa..217d862 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -114,7 +114,6 @@ void _asynctcpsock_task(void *) struct timeval tv; tv.tv_sec = 0; tv.tv_usec = ASYNCTCPSOCK_POLL_INTERVAL * 1000; - uint32_t t1 = millis(); xSemaphoreGiveRecursive(_asyncsock_mutex); @@ -301,7 +300,7 @@ AsyncClient::AsyncClient(int sockfd) { _write_mutex = xSemaphoreCreateMutex(); if (sockfd != -1) { - int r = fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK ); + fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK ); // Updating state visible to asyncTcpSock task xSemaphoreTakeRecursive(_asyncsock_mutex, (TickType_t)portMAX_DELAY); @@ -1244,7 +1243,7 @@ void AsyncServer::begin() log_e("listen error: %d - %s", errno, strerror(errno)); return; } - int r = fcntl(sockfd, F_SETFL, O_NONBLOCK); + fcntl(sockfd, F_SETFL, O_NONBLOCK); // Updating state visible to asyncTcpSock task xSemaphoreTakeRecursive(_asyncsock_mutex, (TickType_t)portMAX_DELAY); From 1212289f0b9bdf81adda4846043be5ff3361070e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Fri, 28 Oct 2022 14:01:55 -0500 Subject: [PATCH 2/2] Skip onPoll processing until socket is fully connected Previously there was a risk that an in-progress connection with a valid socket would be selected for polling and its installed onPoll callback invoked before the onConnect event arrives, resulting in potentially undefined behavior. Fixed by use of the standard connected() method. --- src/AsyncTCP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index 217d862..21d777c 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -898,7 +898,7 @@ void AsyncClient::_sockIsReadable(void) void AsyncClient::_sockPoll(void) { - if (_socket == -1) return; + if (!connected()) return; uint32_t now = millis();