mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Allow to pass timeout to obtainNextWorkingUrl
Sometimes timeout for news in launcher, needs to be investigated
This commit is contained in:
committed by
Mathew Sutcliffe
parent
f7c4292695
commit
640ad99520
@@ -88,6 +88,7 @@ namespace BlackMisc
|
||||
|
||||
bool CNetworkUtils::canConnect(const QString &hostAddress, int port, QString &message, int timeoutMs)
|
||||
{
|
||||
if (timeoutMs < 0) { timeoutMs = getTimeoutMs(); } // external functions might call with -1
|
||||
QTcpSocket socket;
|
||||
QSignalMapper mapper;
|
||||
QObject::connect(&socket, &QTcpSocket::connected, &mapper, QOverload<>::of(&QSignalMapper::map));
|
||||
|
||||
@@ -142,20 +142,19 @@ namespace BlackMisc
|
||||
return (m_failedUrls.size() < this->size() && m_failedUrls.size() < m_maxTrials);
|
||||
}
|
||||
|
||||
CUrl CFailoverUrlList::obtainNextWorkingUrl(bool random, const CUrl &failedUrl)
|
||||
CUrl CFailoverUrlList::obtainNextWorkingUrl(bool random, int connectTimeoutMs)
|
||||
{
|
||||
if (!failedUrl.isEmpty()) { this->addFailedUrl(failedUrl); }
|
||||
if (!hasMoreUrlsToTry()) { return CUrl(); }
|
||||
const CUrl url(this->obtainNextUrlWithout(random, this->m_failedUrls));
|
||||
QString msg;
|
||||
if (CNetworkUtils::canConnect(url, msg)) { return url; }
|
||||
if (CNetworkUtils::canConnect(url, msg, connectTimeoutMs)) { return url; }
|
||||
if (addFailedUrl(url))
|
||||
{
|
||||
if (!msg.isEmpty())
|
||||
{
|
||||
this->m_errorMsgs.append(QString("URL: %1 error: ").arg(url.toQString(), msg));
|
||||
}
|
||||
return obtainNextWorkingUrl();
|
||||
return obtainNextWorkingUrl(random, connectTimeoutMs);
|
||||
}
|
||||
return CUrl();
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace BlackMisc
|
||||
CUrl obtainNextUrlWithout(bool randomStart = false, const CUrlList &exclude = CUrlList()) const;
|
||||
|
||||
//! Next working URL, test if it can be connected
|
||||
CUrl obtainNextWorkingUrl( bool random = false, const CUrl &failedUrl = CUrl());
|
||||
CUrl obtainNextWorkingUrl(bool random = false, int connectTimeoutMs = -1);
|
||||
|
||||
//! Get the error messages
|
||||
const QStringList &getErrorMessages() const { return m_errorMsgs; }
|
||||
|
||||
Reference in New Issue
Block a user