Skip to content

Commit dad8f23

Browse files
fixing reader_th function
when stop() is called on a client when the rxBuffer is not empty the reader thread won't be joined to the main thread due to the logic implemented in the readSocket function
1 parent 105c172 commit dad8f23

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@ uint8_t arduino::MbedClient::status() {
1313
return _status;
1414
}
1515

16+
1617
void arduino::MbedClient::readSocket() {
17-
while (1) {
18+
uint8_t data[SOCKET_BUFFER_SIZE];
19+
20+
while (sock != nullptr) {
1821
event->wait_any(0xFF, 100);
19-
uint8_t data[SOCKET_BUFFER_SIZE];
2022
int ret = NSAPI_ERROR_WOULD_BLOCK;
2123
do {
24+
mutex->lock();
25+
if (sock == nullptr) {
26+
goto cleanup;
27+
}
28+
mutex->unlock();
2229
if (rxBuffer.availableForStore() == 0) {
2330
yield();
2431
continue;
2532
}
2633
mutex->lock();
27-
if (sock == nullptr) {
28-
goto cleanup;
29-
}
3034
ret = sock->recv(data, rxBuffer.availableForStore());
3135
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
3236
goto cleanup;

0 commit comments

Comments
 (0)