From ce72d3d14d7c5f24fa4c9de3a9bfffe105e4588e Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Mon, 7 Aug 2023 13:50:59 +0200 Subject: [PATCH] For the error EWOULDBLOCK try again 10 times until quitting. --- ismas/ismas_client.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ismas/ismas_client.cpp b/ismas/ismas_client.cpp index a842180..2ffa602 100644 --- a/ismas/ismas_client.cpp +++ b/ismas/ismas_client.cpp @@ -148,6 +148,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { int const bytesToWrite = strlen(request.toStdString().c_str()); strncpy(buf, request.toStdString().c_str(), sizeof(buf)-1); + int loop = 0; int bytesWritten = 0; while (bytesWritten < bytesToWrite) { int n = ::sendto(sockfd, buf+bytesWritten, bytesToWrite-bytesWritten, 0, NULL, 0); @@ -155,14 +156,18 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { bytesWritten += n; } else { if (errno == EWOULDBLOCK) { + if (++loop < 10) { + QThread::msleep(500); + continue; + } printErrorMessage(port, clientIP, clientPort, - QString("TIMEOUT (") + strerror(errno) + ")"); + QString("WRITE TIMEOUT %1(").arg(loop) + strerror(errno) + ")"); ::close(sockfd); return std::nullopt; } else if (errno == EINTR) { printErrorMessage(port, clientIP, clientPort, - QString("INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")"); + QString("WRITE INTERRUPTED BY SIGNAL (1) (") + strerror(errno) + ")"); continue; } } @@ -177,6 +182,7 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { printInfoMessage(port, clientIP, clientPort, QString("MESSAGE SENT ") + buf); + loop = 0; bzero(buf, sizeof(buf)); int bytesToRead = sizeof(buf)-1; int bytesRead = 0; @@ -196,8 +202,12 @@ IsmasClient::sendRequestReceiveResponse(int port, QString const &request) { } else if (n < 0) { if (errno == EWOULDBLOCK) { + if (++loop < 10) { + QThread::msleep(500); + continue; + } printErrorMessage(port, clientIP, clientPort, - QString("TIMEOUT (") + strerror(errno) + ")"); + QString("READ TIMEOUT %1(").arg(loop) + strerror(errno) + ")"); ::close(sockfd); return std::nullopt; }