Skip to content

Commit b172e12

Browse files
MbedClient: improving logic of readSocket
1 parent 2d27acf commit b172e12

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ void arduino::MbedClient::readSocket() {
2222
int ret = NSAPI_ERROR_WOULD_BLOCK;
2323
do {
2424
mutex->lock();
25-
if (sock == nullptr) {
26-
goto cleanup;
27-
}
28-
mutex->unlock();
29-
if (rxBuffer.availableForStore() == 0) {
25+
if (sock != nullptr && rxBuffer.availableForStore() == 0) {
26+
mutex->unlock();
3027
yield();
3128
continue;
29+
} else if (sock == nullptr) {
30+
goto cleanup;
3231
}
33-
mutex->lock();
3432
ret = sock->recv(data, rxBuffer.availableForStore());
3533
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
3634
goto cleanup;

0 commit comments

Comments
 (0)