Skip to content

Commit 429c7f1

Browse files
committed
SocketBuffer: revert to non-blocking timeout
1 parent 490c9de commit 429c7f1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
arduino::MbedClient::MbedClient()
88
: _status(false),
9-
_timeout(SOCKET_TIMEOUT) {
9+
_timeout(0) {
1010
}
1111

1212
uint8_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
}
4048
cleanup:
4149
_status = false;
42-
mutex->unlock();
4350
return;
4451
}
4552

@@ -53,7 +60,7 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
5360
}
5461

5562
void 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) {

libraries/SocketWrapper/src/MbedClient.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)