diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2016-04-03 19:26:05 -0500 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2016-04-04 14:18:11 -0700 |
commit | 5821c56da24d0aa02e5bb6d54f14e7651d23269b (patch) | |
tree | 2d42d844bfc632fafbba6fb1eca7fc4d29e6a75f /subsurface-core/checkcloudconnection.cpp | |
parent | 904539024e97b5980050c4ad65a6d2a901f3cb3a (diff) | |
download | subsurface-5821c56da24d0aa02e5bb6d54f14e7651d23269b.tar.gz |
Instrument the git storage code
This allows fairly fine grained analysis on what part of loading from
and saving to git we are spending our time. Compute performance and
network speed play a significant role in how all this plays out.
The routine to check if we can reach the cloud server is modified to
send updates every second so we don't hang without any feedback for five
seconds when there is network but we can't reach the cloud server (not
an unlikely scenario in many dive locations with poor network quality)
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core/checkcloudconnection.cpp')
-rw-r--r-- | subsurface-core/checkcloudconnection.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/subsurface-core/checkcloudconnection.cpp b/subsurface-core/checkcloudconnection.cpp index f028755d0..f29d971ba 100644 --- a/subsurface-core/checkcloudconnection.cpp +++ b/subsurface-core/checkcloudconnection.cpp @@ -6,6 +6,7 @@ #include "pref.h" #include "helpers.h" +#include "git-access.h" #include "checkcloudconnection.h" @@ -22,6 +23,9 @@ CheckCloudConnection::CheckCloudConnection(QObject *parent) : #define MILK "Linus does not like non-fat milk" bool CheckCloudConnection::checkServer() { + if (verbose) + fprintf(stderr, "Checking cloud connection...\n"); + QTimer timer; timer.setSingleShot(true); QEventLoop loop; @@ -35,23 +39,29 @@ bool CheckCloudConnection::checkServer() connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); connect(reply, &QNetworkReply::sslErrors, this, &CheckCloudConnection::sslErrors); - timer.start(5000); // wait five seconds - loop.exec(); - if (timer.isActive()) { - // didn't time out, did we get the right response? - timer.stop(); - if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == HTTP_I_AM_A_TEAPOT && - reply->readAll() == QByteArray(MILK)) { - reply->deleteLater(); - mgr->deleteLater(); - if (verbose > 1) - qWarning() << "Cloud storage: successfully checked connection to cloud server"; - return true; + for (int seconds = 1; seconds <= 5; seconds++) { + timer.start(1000); // wait five seconds + loop.exec(); + if (timer.isActive()) { + // didn't time out, did we get the right response? + timer.stop(); + if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == HTTP_I_AM_A_TEAPOT && + reply->readAll() == QByteArray(MILK)) { + reply->deleteLater(); + mgr->deleteLater(); + if (verbose > 1) + qWarning() << "Cloud storage: successfully checked connection to cloud server"; + git_storage_update_progress(last_git_storage_update_val + 1, "successfully checked cloud connection"); + return true; + } + } else if (seconds < 5) { + git_storage_update_progress(last_git_storage_update_val + 1, "waited 1 sec for cloud connection"); + } else { + disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit())); + reply->abort(); } - } else { - disconnect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - reply->abort(); } + git_storage_update_progress(last_git_storage_update_val + 1, "cloud connection failed"); if (verbose) qDebug() << "connection test to cloud server failed" << reply->error() << reply->errorString() << |