File tree 1 file changed +11
-6
lines changed
libraries/SocketWrapper/src
1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -13,20 +13,24 @@ uint8_t arduino::MbedClient::status() {
13
13
return _status;
14
14
}
15
15
16
+
16
17
void arduino::MbedClient::readSocket () {
17
- while (1 ) {
18
+ uint8_t data[SOCKET_BUFFER_SIZE];
19
+
20
+ while (sock != nullptr ) {
18
21
event->wait_any (0xFF , 100 );
19
- uint8_t data[SOCKET_BUFFER_SIZE];
20
22
int ret = NSAPI_ERROR_WOULD_BLOCK;
21
23
do {
24
+ mutex->lock ();
25
+ if (sock == nullptr ) {
26
+ goto cleanup;
27
+ }
28
+ mutex->unlock ();
22
29
if (rxBuffer.availableForStore () == 0 ) {
23
30
yield ();
24
31
continue ;
25
32
}
26
33
mutex->lock ();
27
- if (sock == nullptr ) {
28
- goto cleanup;
29
- }
30
34
ret = sock->recv (data, rxBuffer.availableForStore ());
31
35
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
32
36
goto cleanup;
@@ -61,7 +65,7 @@ void arduino::MbedClient::configureSocket(Socket *_s) {
61
65
_s->set_timeout (_timeout);
62
66
_s->set_blocking (false );
63
67
_s->getpeername (&address);
64
-
68
+
65
69
if (event == nullptr ) {
66
70
event = new rtos::EventFlags;
67
71
}
@@ -295,6 +299,7 @@ void arduino::MbedClient::stop() {
295
299
mutex = nullptr ;
296
300
}
297
301
_status = false ;
302
+ rxBuffer.clear ();
298
303
}
299
304
300
305
uint8_t arduino::MbedClient::connected () {
You can’t perform that action at this time.
0 commit comments