Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00b5add

Browse files
committed
SocketWrapper MbedClient debugging readSocket
1 parent2ece915 commit00b5add

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

‎libraries/SocketWrapper/src/MbedClient.cpp‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,31 @@ void arduino::MbedClient::readSocket() {
2222
int ret = NSAPI_ERROR_WOULD_BLOCK;
2323
do {
2424
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) {
2630
mutex->unlock();
2731
yield();
2832
continue;
29-
}elseif (sock ==nullptr) {
30-
goto cleanup;
3133
}
3234
ret = sock->recv(data, rxBuffer.availableForStore());
3335
if (ret <0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
36+
mutex->unlock();
3437
goto cleanup;
3538
}
3639
if (ret == NSAPI_ERROR_WOULD_BLOCK || ret ==0) {
37-
yield();
3840
mutex->unlock();
39-
continue;
41+
yield();
42+
break;
4043
}
4144
for (int i =0; i < ret; i++) {
4245
rxBuffer.store_char(data[i]);
4346
}
4447
mutex->unlock();
4548
_status =true;
46-
}while (ret == NSAPI_ERROR_WOULD_BLOCK || ret >0);
49+
}while (true);
4750
}
4851
cleanup:
4952
_status =false;
@@ -98,6 +101,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
98101
}
99102

100103
if (static_cast<TCPSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
104+
_status =false;
101105
return0;
102106
}
103107

@@ -117,6 +121,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
117121
configureSocket(sock);
118122
_status =true;
119123
}else {
124+
sock->close();
120125
_status =false;
121126
}
122127

@@ -148,6 +153,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
148153
}
149154

150155
if (static_cast<TLSSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
156+
_status =false;
151157
return0;
152158
}
153159

@@ -179,6 +185,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
179185
configureSocket(sock);
180186
_status =true;
181187
}else {
188+
sock->close();
182189
_status =false;
183190
}
184191

@@ -209,12 +216,14 @@ size_t arduino::MbedClient::write(uint8_t c) {
209216
}
210217

211218
size_tarduino::MbedClient::write(constuint8_t *buf,size_t size) {
212-
if (sock ==nullptr)
219+
if (_status ==false)
213220
return0;
214221

222+
mutex->lock();
215223
sock->set_timeout(_timeout);
216224
int ret = sock->send(buf, size);
217225
sock->set_blocking(false);
226+
mutex->unlock();
218227
return ret >=0 ? ret :0;
219228
}
220229

@@ -224,7 +233,7 @@ int arduino::MbedClient::available() {
224233
}
225234

226235
intarduino::MbedClient::read() {
227-
if (sock ==nullptr)
236+
if (_status ==false)
228237
return -1;
229238
mutex->lock();
230239
if (!available()) {
@@ -238,7 +247,7 @@ int arduino::MbedClient::read() {
238247
}
239248

240249
intarduino::MbedClient::read(uint8_t *data,size_t len) {
241-
if (sock ==nullptr)
250+
if (_status ==false)
242251
return0;
243252
mutex->lock();
244253
int avail =available();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp