Skip to content

Commit

Permalink
Retry send up to 5 times, then close socket
Browse files Browse the repository at this point in the history
  • Loading branch information
giulcioffi authored and aentinger committed Jan 28, 2021
1 parent 08f534e commit f4c37bb
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,29 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) {
if (size==0)
{
setWriteError();
return 0;
return 0;
}

size_t written = ServerDrv::sendData(_sock, buf, size);
if (!written)
{
setWriteError();
return 0;
bool success = false;
size_t written = 0;
for (int i=0; i<5; i++) {
written = ServerDrv::sendData(_sock, buf, size);
if (written) {
success = true;
break;
}
}
if (!ServerDrv::checkDataSent(_sock))
{
setWriteError();
return 0;
if (success) {
if (!ServerDrv::checkDataSent(_sock))
{
setWriteError();
return 0;
}
} else {
// close socket
ServerDrv::stopClient(_sock);
setWriteError();
return 0;
}

return written;
Expand Down

0 comments on commit f4c37bb

Please sign in to comment.