File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed
libraries/SocketWrapper/src Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change 66
77arduino::MbedClient::MbedClient ()
88 : _status(false ),
9- _timeout(SOCKET_TIMEOUT ) {
9+ _timeout(0 ) {
1010}
1111
1212uint8_t arduino::MbedClient::status () {
@@ -19,27 +19,34 @@ void arduino::MbedClient::readSocket() {
1919 uint8_t data[SOCKET_BUFFER_SIZE];
2020 int ret = NSAPI_ERROR_WOULD_BLOCK;
2121 do {
22- mutex->lock ();
2322 if (rxBuffer.availableForStore () == 0 ) {
2423 yield ();
24+ delay (100 );
25+ continue ;
2526 }
27+ mutex->lock ();
2628 if (sock == nullptr || (closing && borrowed_socket)) {
2729 goto cleanup;
2830 }
2931 ret = sock->recv (data, rxBuffer.availableForStore ());
3032 if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
3133 goto cleanup;
3234 }
35+ if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0 ) {
36+ yield ();
37+ delay (100 );
38+ mutex->unlock ();
39+ continue ;
40+ }
3341 for (int i = 0 ; i < ret; i++) {
3442 rxBuffer.store_char (data[i]);
3543 }
36- _status = true ;
3744 mutex->unlock ();
45+ _status = true ;
3846 } while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0 );
3947 }
4048cleanup:
4149 _status = false ;
42- mutex->unlock ();
4350 return ;
4451}
4552
@@ -53,7 +60,7 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
5360}
5461
5562void arduino::MbedClient::configureSocket (Socket *_s) {
56- _s->set_timeout (SOCKET_TIMEOUT );
63+ _s->set_timeout (_timeout );
5764 _s->set_blocking (false );
5865
5966 if (event == nullptr ) {
Original file line number Diff line number Diff line change @@ -87,7 +87,6 @@ class MbedClient : public arduino::Client {
8787
8888 void setSocket (Socket* _sock);
8989 Socket* getSocket () { return sock; };
90- RingBufferN<SOCKET_BUFFER_SIZE> *getRxBuffer () { return &rxBuffer; };
9190
9291 void configureSocket (Socket* _s);
9392
You can’t perform that action at this time.
0 commit comments