From b172e128592f879bac618a1fa4b77d008a83a3c5 Mon Sep 17 00:00:00 2001 From: Andrea Gilardoni Date: Tue, 23 Apr 2024 11:26:12 +0200 Subject: [PATCH] MbedClient: improving logic of readSocket --- libraries/SocketWrapper/src/MbedClient.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index 06427b293..49188df7e 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -22,15 +22,13 @@ void arduino::MbedClient::readSocket() { int ret = NSAPI_ERROR_WOULD_BLOCK; do { mutex->lock(); - if (sock == nullptr) { - goto cleanup; - } - mutex->unlock(); - if (rxBuffer.availableForStore() == 0) { + if (sock != nullptr && rxBuffer.availableForStore() == 0) { + mutex->unlock(); yield(); continue; + } else if (sock == nullptr) { + goto cleanup; } - mutex->lock(); ret = sock->recv(data, rxBuffer.availableForStore()); if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) { goto cleanup;