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 00bc011

Browse files
SocketWrapper MbedClient debugging readSocket
1 parent 2ece915 commit 00bc011

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

‎libraries/SocketWrapper/src/MbedClient.cpp‎

Lines changed: 17 additions & 10 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

@@ -209,12 +215,13 @@ size_t arduino::MbedClient::write(uint8_t c) {
209215
}
210216

211217
size_t arduino::MbedClient::write(const uint8_t *buf, size_t size) {
212-
if (sock == nullptr)
218+
if (mutex == nullptr)
213219
return 0;
214-
220+
mutex->lock();
215221
sock->set_timeout(_timeout);
216222
int ret = sock->send(buf, size);
217223
sock->set_blocking(false);
224+
mutex->unlock();
218225
return ret >= 0 ? ret : 0;
219226
}
220227

@@ -224,7 +231,7 @@ int arduino::MbedClient::available() {
224231
}
225232

226233
int arduino::MbedClient::read() {
227-
if (sock == nullptr)
234+
if (mutex == nullptr)
228235
return -1;
229236
mutex->lock();
230237
if (!available()) {
@@ -238,7 +245,7 @@ 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;
243250
mutex->lock();
244251
int avail = available();

0 commit comments

Comments
(0)

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