diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index cce392b12..f9dcdad52 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -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; } @@ -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; diff --git a/libraries/SocketWrapper/src/MbedClient.h b/libraries/SocketWrapper/src/MbedClient.h index cd9929839..662e10473 100644 --- a/libraries/SocketWrapper/src/MbedClient.h +++ b/libraries/SocketWrapper/src/MbedClient.h @@ -89,6 +89,10 @@ class MbedClient : public arduino::Client { return sock != nullptr; } + void registerDataAvailableCb(mbed::Callback cb) { + _data_available_cb = cb; + } + void setSocket(Socket* _sock); Socket* getSocket() { return sock; }; @@ -114,6 +118,7 @@ class MbedClient : public arduino::Client { } private: + mbed::Callback _data_available_cb; RingBufferN rxBuffer; bool _status = false; bool borrowed_socket = false;