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
This commit is contained in:
@@ -13,20 +13,24 @@ uint8_t arduino::MbedClient::status() {
|
||||
return _status;
|
||||
}
|
||||
|
||||
|
||||
void arduino::MbedClient::readSocket() {
|
||||
while (1) {
|
||||
uint8_t data[SOCKET_BUFFER_SIZE];
|
||||
|
||||
while (sock != nullptr) {
|
||||
event->wait_any(0xFF, 100);
|
||||
uint8_t data[SOCKET_BUFFER_SIZE];
|
||||
int ret = NSAPI_ERROR_WOULD_BLOCK;
|
||||
do {
|
||||
mutex->lock();
|
||||
if (sock == nullptr) {
|
||||
goto cleanup;
|
||||
}
|
||||
mutex->unlock();
|
||||
if (rxBuffer.availableForStore() == 0) {
|
||||
yield();
|
||||
continue;
|
||||
}
|
||||
mutex->lock();
|
||||
if (sock == nullptr) {
|
||||
goto cleanup;
|
||||
}
|
||||
ret = sock->recv(data, rxBuffer.availableForStore());
|
||||
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
|
||||
goto cleanup;
|
||||
|
||||
Reference in New Issue
Block a user