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

Notify when there is data in socket rx buffer #831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ void arduino::MbedClient::readSocket() {
int ret = NSAPI_ERROR_WOULD_BLOCK;
do {
if (rxBuffer.availableForStore() == 0) {
// Notify that the buffer is full and data needs to be processed
if (_data_available_cb) {
_data_available_cb();
}
yield();
continue;
}
Expand All @@ -42,6 +46,10 @@ void arduino::MbedClient::readSocket() {
mutex->unlock();
_status = true;
} while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0);
// Notify about data in RX Buffer
if (_data_available_cb) {
_data_available_cb();
}
}
cleanup:
_status = false;
Expand Down
5 changes: 5 additions & 0 deletions libraries/SocketWrapper/src/MbedClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class MbedClient : public arduino::Client {
return sock != nullptr;
}

void registerDataAvailableCb(mbed::Callback<void(void)> cb) {
_data_available_cb = cb;
}

void setSocket(Socket* _sock);
Socket* getSocket() { return sock; };

Expand All @@ -114,6 +118,7 @@ class MbedClient : public arduino::Client {
}

private:
mbed::Callback<void(void)> _data_available_cb;
RingBufferN<SOCKET_BUFFER_SIZE> rxBuffer;
bool _status = false;
bool borrowed_socket = false;
Expand Down
Loading