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

Commit 3428d75

Browse files
SocketWrapper MbedClient debugging readSocket
1 parent 2ece915 commit 3428d75

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

‎libraries/SocketWrapper/src/MbedClient.cpp‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@ 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-
} else if (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+
break;
4042
}
4143
for (int i = 0; i < ret; i++) {
4244
rxBuffer.store_char(data[i]);
4345
}
4446
mutex->unlock();
4547
_status = true;
46-
} while (ret == NSAPI_ERROR_WOULD_BLOCK || ret > 0);
48+
} while (true);
4749
}
4850
cleanup:
4951
_status = false;
@@ -98,6 +100,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
98100
}
99101

100102
if (static_cast<TCPSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
103+
_status = false;
101104
return 0;
102105
}
103106

@@ -117,6 +120,7 @@ int arduino::MbedClient::connect(SocketAddress socketAddress) {
117120
configureSocket(sock);
118121
_status = true;
119122
} else {
123+
sock->close();
120124
_status = false;
121125
}
122126

@@ -148,6 +152,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
148152
}
149153

150154
if (static_cast<TLSSocket *>(sock)->open(getNetwork()) != NSAPI_ERROR_OK) {
155+
_status = false;
151156
return 0;
152157
}
153158

@@ -179,6 +184,7 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) {
179184
configureSocket(sock);
180185
_status = true;
181186
} else {
187+
sock->close();
182188
_status = false;
183189
}
184190

@@ -224,8 +230,9 @@ int arduino::MbedClient::available() {
224230
}
225231

226232
int arduino::MbedClient::read() {
227-
if (sock == nullptr)
233+
if (mutex == nullptr) {
228234
return -1;
235+
}
229236
mutex->lock();
230237
if (!available()) {
231238
mutex->unlock();
@@ -238,8 +245,9 @@ int arduino::MbedClient::read() {
238245
}
239246

240247
int arduino::MbedClient::read(uint8_t *data, size_t len) {
241-
if (sock == nullptr)
248+
if (mutex == nullptr) {
242249
return 0;
250+
}
243251
mutex->lock();
244252
int avail = available();
245253

@@ -261,7 +269,14 @@ int arduino::MbedClient::read(uint8_t *data, size_t len) {
261269
}
262270

263271
int arduino::MbedClient::peek() {
264-
return rxBuffer.peek();
272+
if (mutex == nullptr) {
273+
return 0;
274+
}
275+
mutex->lock();
276+
int res = rxBuffer.peek();
277+
mutex->unlock();
278+
279+
return res;
265280
}
266281

267282
void arduino::MbedClient::flush() {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /