Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mbedclient stop issue #868

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +65,7 @@ void arduino::MbedClient::configureSocket(Socket *_s) {
_s->set_timeout(_timeout);
_s->set_blocking(false);
_s->getpeername(&address);

if (event == nullptr) {
event = new rtos::EventFlags;
}
Expand Down Expand Up @@ -295,6 +299,7 @@ void arduino::MbedClient::stop() {
mutex = nullptr;
}
_status = false;
rxBuffer.clear();
}

uint8_t arduino::MbedClient::connected() {
Expand Down
Loading