File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
libraries/SocketWrapper/src Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -22,28 +22,31 @@ void arduino::MbedClient::readSocket() {
22
22
int ret = NSAPI_ERROR_WOULD_BLOCK;
23
23
do {
24
24
mutex->lock ();
25
- if (sock != nullptr && rxBuffer.availableForStore () == 0 ) {
25
+ if (sock == nullptr ) {
26
+ mutex->unlock ();
27
+ goto cleanup;
28
+ }
29
+ if (rxBuffer.availableForStore () == 0 ) {
26
30
mutex->unlock ();
27
31
yield ();
28
32
continue ;
29
- } else if (sock == nullptr ) {
30
- goto cleanup;
31
33
}
32
34
ret = sock->recv (data, rxBuffer.availableForStore ());
33
35
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
36
+ mutex->unlock ();
34
37
goto cleanup;
35
38
}
36
39
if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0 ) {
37
- yield ();
38
40
mutex->unlock ();
39
- continue ;
41
+ yield ();
42
+ break ;
40
43
}
41
44
for (int i = 0 ; i < ret; i++) {
42
45
rxBuffer.store_char (data[i]);
43
46
}
44
47
mutex->unlock ();
45
48
_status = true ;
46
- } while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0 );
49
+ } while (true );
47
50
}
48
51
cleanup:
49
52
_status = false ;
@@ -117,6 +120,8 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
117
120
configureSocket (sock);
118
121
_status = true ;
119
122
} else {
123
+ delete sock;
124
+ sock = nullptr ;
120
125
_status = false ;
121
126
}
122
127
@@ -212,9 +217,11 @@ size_t arduino::MbedClient::write(const uint8_t *buf, size_t size) {
212
217
if (sock == nullptr )
213
218
return 0 ;
214
219
220
+ mutex->lock ();
215
221
sock->set_timeout (_timeout);
216
222
int ret = sock->send (buf, size);
217
223
sock->set_blocking (false );
224
+ mutex->unlock ();
218
225
return ret >= 0 ? ret : 0 ;
219
226
}
220
227
You can’t perform that action at this time.
0 commit comments