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 6
6
7
7
arduino::MbedClient::MbedClient ()
8
8
: _status(false ),
9
- _timeout(SOCKET_TIMEOUT ) {
9
+ _timeout(0 ) {
10
10
}
11
11
12
12
uint8_t arduino::MbedClient::status () {
@@ -19,27 +19,34 @@ void arduino::MbedClient::readSocket() {
19
19
uint8_t data[SOCKET_BUFFER_SIZE];
20
20
int ret = NSAPI_ERROR_WOULD_BLOCK;
21
21
do {
22
- mutex->lock ();
23
22
if (rxBuffer.availableForStore () == 0 ) {
24
23
yield ();
24
+ delay (100 );
25
+ continue ;
25
26
}
27
+ mutex->lock ();
26
28
if (sock == nullptr || (closing && borrowed_socket)) {
27
29
goto cleanup;
28
30
}
29
31
ret = sock->recv (data, rxBuffer.availableForStore ());
30
32
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
31
33
goto cleanup;
32
34
}
35
+ if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0 ) {
36
+ yield ();
37
+ delay (100 );
38
+ mutex->unlock ();
39
+ continue ;
40
+ }
33
41
for (int i = 0 ; i < ret; i++) {
34
42
rxBuffer.store_char (data[i]);
35
43
}
36
- _status = true ;
37
44
mutex->unlock ();
45
+ _status = true ;
38
46
} while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0 );
39
47
}
40
48
cleanup:
41
49
_status = false ;
42
- mutex->unlock ();
43
50
return ;
44
51
}
45
52
@@ -53,7 +60,7 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
53
60
}
54
61
55
62
void arduino::MbedClient::configureSocket (Socket *_s) {
56
- _s->set_timeout (SOCKET_TIMEOUT );
63
+ _s->set_timeout (_timeout );
57
64
_s->set_blocking (false );
58
65
59
66
if (event == nullptr ) {
Original file line number Diff line number Diff line change @@ -87,7 +87,6 @@ class MbedClient : public arduino::Client {
87
87
88
88
void setSocket (Socket* _sock);
89
89
Socket* getSocket () { return sock; };
90
- RingBufferN<SOCKET_BUFFER_SIZE> *getRxBuffer () { return &rxBuffer; };
91
90
92
91
void configureSocket (Socket* _s);
93
92
You can’t perform that action at this time.
0 commit comments