Skip to content

Commit 957275d

Browse files
committed
SocketWrapper MbedClient debugging readSocket
1 parent 2ece915 commit 957275d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,31 @@ void arduino::MbedClient::readSocket() {
2222
int ret = NSAPI_ERROR_WOULD_BLOCK;
2323
do {
2424
mutex->lock();
25-
if (sock != nullptr && rxBuffer.availableForStore() == 0) {
25+
if (sock == nullptr) {
26+
mutex->unlock();
27+
goto cleanup;
28+
}
29+
if (rxBuffer.availableForStore() == 0) {
2630
mutex->unlock();
2731
yield();
2832
continue;
29-
} else if (sock == nullptr) {
30-
goto cleanup;
3133
}
3234
ret = sock->recv(data, rxBuffer.availableForStore());
3335
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
36+
mutex->unlock();
3437
goto cleanup;
3538
}
3639
if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0) {
37-
yield();
3840
mutex->unlock();
39-
continue;
41+
yield();
42+
break;
4043
}
4144
for (int i = 0; i < ret; i++) {
4245
rxBuffer.store_char(data[i]);
4346
}
4447
mutex->unlock();
4548
_status = true;
46-
} while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0);
49+
} while (true);
4750
}
4851
cleanup:
4952
_status = false;
@@ -117,6 +120,8 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
117120
configureSocket(sock);
118121
_status = true;
119122
} else {
123+
delete sock;
124+
sock = nullptr;
120125
_status = false;
121126
}
122127

@@ -212,9 +217,11 @@ size_t arduino::MbedClient::write(const uint8_t *buf, size_t size) {
212217
if (sock == nullptr)
213218
return 0;
214219

220+
mutex->lock();
215221
sock->set_timeout(_timeout);
216222
int ret = sock->send(buf, size);
217223
sock->set_blocking(false);
224+
mutex->unlock();
218225
return ret >= 0 ? ret : 0;
219226
}
220227

0 commit comments

Comments
 (0)