Refactored host connectivity check into a separate function. Also decrease the number of remaining connection attempts *only* if the connection failed.
This commit is contained in:
parent
ad9e7e0d77
commit
4ccad3655b
@ -252,7 +252,7 @@ void UpdateCheckThread::checkForUpdates(void)
|
|||||||
// ----- Test Internet Connection ----- //
|
// ----- Test Internet Connection ----- //
|
||||||
|
|
||||||
int connectionScore = 0;
|
int connectionScore = 0;
|
||||||
int maxConnectTries = 2 * MIN_CONNSCORE;
|
int maxConnectTries = (3 * MIN_CONNSCORE) / 2;
|
||||||
|
|
||||||
log("Checking internet connection...");
|
log("Checking internet connection...");
|
||||||
setStatus(UpdateStatus_CheckingConnection);
|
setStatus(UpdateStatus_CheckingConnection);
|
||||||
@ -278,29 +278,21 @@ void UpdateCheckThread::checkForUpdates(void)
|
|||||||
|
|
||||||
x264_seed_rand();
|
x264_seed_rand();
|
||||||
|
|
||||||
while(!(hostList.isEmpty() || (connectionScore >= MIN_CONNSCORE) || (--maxConnectTries < 0)))
|
while(!(hostList.isEmpty() || (connectionScore >= MIN_CONNSCORE) || (maxConnectTries < 1)))
|
||||||
{
|
{
|
||||||
QString currentHost = hostList.takeAt(x264_rand() % hostList.count());
|
switch(tryContactHost(hostList.takeAt(x264_rand() % hostList.count())))
|
||||||
log("", "Testing host:", currentHost);
|
|
||||||
QString outFile = QString("%1/%2.htm").arg(x264_temp_directory(), x264_rand_str());
|
|
||||||
bool httpOk = false;
|
|
||||||
if(getFile(currentHost, outFile, 0, &httpOk))
|
|
||||||
{
|
{
|
||||||
connectionScore++;
|
case 01: connectionScore += 1; break;
|
||||||
|
case 02: connectionScore += 2; break;
|
||||||
|
default: maxConnectTries -= 1; break;
|
||||||
|
}
|
||||||
setProgress(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
|
setProgress(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
|
||||||
x264_sleep(64);
|
x264_sleep(64);
|
||||||
}
|
}
|
||||||
if(httpOk)
|
|
||||||
{
|
|
||||||
connectionScore++;
|
|
||||||
setProgress(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
|
|
||||||
x264_sleep(64);
|
|
||||||
}
|
|
||||||
QFile::remove(outFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(connectionScore < MIN_CONNSCORE)
|
if(connectionScore < MIN_CONNSCORE)
|
||||||
{
|
{
|
||||||
|
log("", "Connectivity test has failed: Internet connection appears to be broken!");
|
||||||
setProgress(m_maxProgress);
|
setProgress(m_maxProgress);
|
||||||
setStatus(UpdateStatus_ErrorConnectionTestFailed);
|
setStatus(UpdateStatus_ErrorConnectionTestFailed);
|
||||||
return;
|
return;
|
||||||
@ -439,6 +431,35 @@ void UpdateCheckThread::log(const QString &str1, const QString &str2, const QStr
|
|||||||
if(!str4.isNull()) emit messageLogged(str4);
|
if(!str4.isNull()) emit messageLogged(str4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UpdateCheckThread::tryContactHost(const QString &url)
|
||||||
|
{
|
||||||
|
int result = -1; bool httpOkay = false;
|
||||||
|
const QString outFile = QString("%1/%2.htm").arg(x264_temp_directory(), x264_rand_str());
|
||||||
|
log("", "Testing host:", url);
|
||||||
|
|
||||||
|
if(getFile(url, outFile, 0, &httpOkay))
|
||||||
|
{
|
||||||
|
log("Connection to host was established successfully.");
|
||||||
|
result = 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(httpOkay)
|
||||||
|
{
|
||||||
|
log("Connection to host timed out after HTTP OK was received.");
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log("Connection failed: The host could not be reached!");
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile::remove(outFile);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool UpdateCheckThread::tryUpdateMirror(UpdateInfo *updateInfo, const QString &url)
|
bool UpdateCheckThread::tryUpdateMirror(UpdateInfo *updateInfo, const QString &url)
|
||||||
{
|
{
|
||||||
bool success = false;
|
bool success = false;
|
||||||
@ -497,7 +518,7 @@ bool UpdateCheckThread::getFile(const QString &url, const QString &outFile, unsi
|
|||||||
x264_init_process(process, output.absolutePath());
|
x264_init_process(process, output.absolutePath());
|
||||||
|
|
||||||
QStringList args;
|
QStringList args;
|
||||||
args << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
|
args << "-T" << "15" << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
|
||||||
args << QString("--referer=%1://%2/").arg(QUrl(url).scheme(), QUrl(url).host()) << "-U" << USER_AGENT_STR;
|
args << QString("--referer=%1://%2/").arg(QUrl(url).scheme(), QUrl(url).host()) << "-U" << USER_AGENT_STR;
|
||||||
args << "-O" << output.fileName() << url;
|
args << "-O" << output.fileName() << url;
|
||||||
|
|
||||||
@ -522,10 +543,10 @@ bool UpdateCheckThread::getFile(const QString &url, const QString &outFile, unsi
|
|||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
while(process.state() == QProcess::Running)
|
while(process.state() != QProcess::NotRunning)
|
||||||
{
|
{
|
||||||
loop.exec();
|
loop.exec();
|
||||||
bool bTimeOut = (!timer.isActive());
|
const bool bTimeOut = (!timer.isActive());
|
||||||
while(process.canReadLine())
|
while(process.canReadLine())
|
||||||
{
|
{
|
||||||
QString line = QString::fromLatin1(process.readLine()).simplified();
|
QString line = QString::fromLatin1(process.readLine()).simplified();
|
||||||
|
@ -101,6 +101,7 @@ private:
|
|||||||
inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
|
inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
|
||||||
|
|
||||||
bool getFile(const QString &url, const QString &outFile, unsigned int maxRedir = 5, bool *httpOk = NULL);
|
bool getFile(const QString &url, const QString &outFile, unsigned int maxRedir = 5, bool *httpOk = NULL);
|
||||||
|
int tryContactHost(const QString &url);
|
||||||
bool tryUpdateMirror(UpdateInfo *updateInfo, const QString &url);
|
bool tryUpdateMirror(UpdateInfo *updateInfo, const QString &url);
|
||||||
bool checkSignature(const QString &file, const QString &signature);
|
bool checkSignature(const QString &file, const QString &signature);
|
||||||
bool parseVersionInfo(const QString &file, UpdateInfo *updateInfo);
|
bool parseVersionInfo(const QString &file, UpdateInfo *updateInfo);
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#define VER_X264_MAJOR 2
|
#define VER_X264_MAJOR 2
|
||||||
#define VER_X264_MINOR 3
|
#define VER_X264_MINOR 3
|
||||||
#define VER_X264_PATCH 0
|
#define VER_X264_PATCH 0
|
||||||
#define VER_X264_BUILD 750
|
#define VER_X264_BUILD 751
|
||||||
|
|
||||||
#define VER_X264_MINIMUM_REV 2380
|
#define VER_X264_MINIMUM_REV 2380
|
||||||
#define VER_X264_CURRENT_API 142
|
#define VER_X264_CURRENT_API 142
|
||||||
|
Loading…
Reference in New Issue
Block a user