Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Socket Write Hangs Indefinitely When There Is No Connectivity #906

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading