Skip to content

Commit

Permalink
Merge pull request #906 from pennam/write-fix
Browse files Browse the repository at this point in the history
Fix Socket Write Hangs Indefinitely When There Is No Connectivity
  • Loading branch information
pennam committed Jun 28, 2024
2 parents 546529a + 70e3d5d commit 9194e32
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions libraries/SocketWrapper/src/MbedClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

arduino::MbedClient::MbedClient()
: _status(false),
_timeout(0) {
_timeout(SOCKET_TIMEOUT) {
}

uint8_t arduino::MbedClient::status() {
Expand Down Expand Up @@ -60,7 +60,6 @@ void arduino::MbedClient::setSocket(Socket *_sock) {
}

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

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

sock->set_blocking(true);
sock->set_timeout(SOCKET_TIMEOUT);
int ret = NSAPI_ERROR_WOULD_BLOCK;
do {
ret = sock->send(buf, size);
} while ((ret != size && ret == NSAPI_ERROR_WOULD_BLOCK) && connected());
configureSocket(sock);
return size;
sock->set_timeout(_timeout);
int ret = sock->send(buf, size);
sock->set_blocking(false);
return ret >= 0 ? ret : 0;
}

int arduino::MbedClient::available() {
Expand Down

0 comments on commit 9194e32

Please sign in to comment.