Skip to content

Commit 8186f2a

Browse files
authored
Merge pull request #868 from andreagilardoni/mbedclient-stop-issue
Mbedclient stop issue
2 parents 79d9a8d + abaef3f commit 8186f2a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

+11-6
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;
@@ -61,7 +65,7 @@ void arduino::MbedClient::configureSocket(Socket *_s) {
6165
_s->set_timeout(_timeout);
6266
_s->set_blocking(false);
6367
_s->getpeername(&address);
64-
68+
6569
if (event == nullptr) {
6670
event = new rtos::EventFlags;
6771
}
@@ -295,6 +299,7 @@ void arduino::MbedClient::stop() {
295299
mutex = nullptr;
296300
}
297301
_status = false;
302+
rxBuffer.clear();
298303
}
299304

300305
uint8_t arduino::MbedClient::connected() {

0 commit comments

Comments
 (0)