Skip to content

Commit 9194e32

Browse files
authoredJun 28, 2024··
Merge pull request #906 from pennam/write-fix
Fix Socket Write Hangs Indefinitely When There Is No Connectivity
2 parents 546529a + 70e3d5d commit 9194e32

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed
 

‎libraries/SocketWrapper/src/MbedClient.cpp

+5-10
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
arduino::MbedClient::MbedClient()
88
: _status(false),
9-
_timeout(0) {
9+
_timeout(SOCKET_TIMEOUT) {
1010
}
1111

1212
uint8_t arduino::MbedClient::status() {
@@ -60,7 +60,6 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
6060
}
6161

6262
void arduino::MbedClient::configureSocket(Socket *_s) {
63-
_s->set_timeout(_timeout);
6463
_s->set_blocking(false);
6564
_s->getpeername(&address);
6665

@@ -213,14 +212,10 @@ size_t arduino::MbedClient::write(const uint8_t *buf, size_t size) {
213212
if (sock == nullptr)
214213
return 0;
215214

216-
sock->set_blocking(true);
217-
sock->set_timeout(SOCKET_TIMEOUT);
218-
int ret = NSAPI_ERROR_WOULD_BLOCK;
219-
do {
220-
ret = sock->send(buf, size);
221-
} while ((ret != size && ret == NSAPI_ERROR_WOULD_BLOCK) && connected());
222-
configureSocket(sock);
223-
return size;
215+
sock->set_timeout(_timeout);
216+
int ret = sock->send(buf, size);
217+
sock->set_blocking(false);
218+
return ret >= 0 ? ret : 0;
224219
}
225220

226221
int arduino::MbedClient::available() {

0 commit comments

Comments
 (0)
Please sign in to comment.