Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
fix:limit timeout 30s
Browse files Browse the repository at this point in the history
添加限制超时时间30秒 task:21941
  • Loading branch information
zhaolong committed May 20, 2020
1 parent 7038d0f commit 12cc5a1
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions connectivitychecker.cpp
Expand Up @@ -36,6 +36,7 @@ static const QStringList CheckUrls {
};

#define TIMERINTERVAL (60 * 1000) // 一分钟
#define TIMEOUT (30 * 1000) // 30s超时

using namespace dde::network;

Expand Down Expand Up @@ -76,17 +77,26 @@ void ConnectivityChecker::startCheck()
// reply->waitForReadyRead(-1);

// Blocking, about 30 second to timeout
QTimer timer;
timer.setSingleShot(true);
QEventLoop synchronous;
connect(&timer, &QTimer::timeout, &synchronous, &QEventLoop::quit);
connect(&nam, &QNetworkAccessManager::finished, &synchronous, &QEventLoop::quit);
timer.start(TIMEOUT);
synchronous.exec();

reply->close();
if (reply->error() == QNetworkReply::NoError &&
(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200 ||
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 204)) {
qDebug() << "Connected to url:" << url;
Q_EMIT checkFinished(true);
return;
if (timer.isActive()) {
timer.stop();
if (reply->error() == QNetworkReply::NoError &&
(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200 ||
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 204)) {
qDebug() << "Connected to url:" << url;
Q_EMIT checkFinished(true);
return;
}
} else {
qDebug() << "Timeout";
}

qDebug() << "Failed to connect url:" << url;
Expand Down

0 comments on commit 12cc5a1

Please sign in to comment.