two different timeouts, first is horter, second one is longer (1s/9s); second try includes direct and default proxy again
This commit is contained in:
@@ -85,7 +85,9 @@ namespace proxy {
|
|||||||
//! Keep your instance as long as possible, because of caching.
|
//! Keep your instance as long as possible, because of caching.
|
||||||
Interface() {
|
Interface() {
|
||||||
#ifdef QT_NETWORK_LIB
|
#ifdef QT_NETWORK_LIB
|
||||||
if (!connect(&_timeout, SIGNAL(timeout()), SLOT(timeout())))
|
if (!connect(&_timeout1, SIGNAL(timeout()), SLOT(timeout())))
|
||||||
|
qFatal("connect failed");
|
||||||
|
if (!connect(&_timeout2, SIGNAL(timeout()), SLOT(timeout())))
|
||||||
qFatal("connect failed");
|
qFatal("connect failed");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -104,10 +106,11 @@ namespace proxy {
|
|||||||
|
|
||||||
@param url the url to find a proxy for
|
@param url the url to find a proxy for
|
||||||
@param timeout [ms] time to give up search */
|
@param timeout [ms] time to give up search */
|
||||||
void proxy(const std::string& url, int timeout=2000) {
|
void proxy(const std::string& url, int timeout1=1000, int timeout2=9000) {
|
||||||
qDebug()<<"Search proxy for URL, direct and default"
|
qDebug()<<"Search proxy for URL, direct and default"
|
||||||
<<"url="<<url.data()<<"timeout="<<timeout;
|
<<"url="<<url.data()<<"timeout1="<<timeout1;
|
||||||
for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it)
|
for (Requests::iterator it(_requests.begin());
|
||||||
|
it!=_requests.end(); ++it)
|
||||||
delete it->second.first;
|
delete it->second.first;
|
||||||
_requests.clear();
|
_requests.clear();
|
||||||
_direct = true; // first try direct access
|
_direct = true; // first try direct access
|
||||||
@@ -115,19 +118,21 @@ namespace proxy {
|
|||||||
setupProxyCheck(directProxy, url);
|
setupProxyCheck(directProxy, url);
|
||||||
QNetworkProxy defaultProxy;
|
QNetworkProxy defaultProxy;
|
||||||
setupProxyCheck(defaultProxy, url);
|
setupProxyCheck(defaultProxy, url);
|
||||||
_timeout.setSingleShot(true);
|
_timeout2.setSingleShot(true);
|
||||||
_timeout.setInterval(timeout);
|
_timeout2.setInterval(timeout2);
|
||||||
_timeout.start();
|
_timeout1.setSingleShot(true);
|
||||||
|
_timeout1.setInterval(timeout1);
|
||||||
|
_timeout1.start();
|
||||||
}
|
}
|
||||||
//! If Qt Network is available you may check the proxies found
|
//! If Qt Network is available you may check the proxies found
|
||||||
/*! @copydoc proxy(const std::string&, int) */
|
/*! @copydoc proxy(const std::string&, int) */
|
||||||
void proxy(const QUrl& url, int timeout=2000) {
|
void proxy(const QUrl& url, int timeout1=1000, int timeout2=9000) {
|
||||||
proxy(url.toString().toStdString(), timeout);
|
proxy(url.toString().toStdString(), timeout1, timeout2);
|
||||||
}
|
}
|
||||||
//! If Qt Network is available you may check the proxies found
|
//! If Qt Network is available you may check the proxies found
|
||||||
/*! @copydoc proxy(const std::string&, int) */
|
/*! @copydoc proxy(const std::string&, int) */
|
||||||
void proxy(const QString& url, int timeout=2000) {
|
void proxy(const QString& url, int timeout1=1000, int timeout2=9000) {
|
||||||
proxy(url.toStdString(), timeout);
|
proxy(url.toStdString(), timeout1, timeout2);
|
||||||
}
|
}
|
||||||
static QString toString(const QNetworkProxy& p) {
|
static QString toString(const QNetworkProxy& p) {
|
||||||
switch (p.type()) {
|
switch (p.type()) {
|
||||||
@@ -174,7 +179,8 @@ namespace proxy {
|
|||||||
}
|
}
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void timeout() {
|
void timeout() {
|
||||||
_timeout.stop();
|
_timeout1.stop();
|
||||||
|
_timeout2.stop();
|
||||||
std::string url;
|
std::string url;
|
||||||
for (Requests::iterator it(_requests.begin());
|
for (Requests::iterator it(_requests.begin());
|
||||||
it!=_requests.end(); ++it) {
|
it!=_requests.end(); ++it) {
|
||||||
@@ -196,7 +202,11 @@ namespace proxy {
|
|||||||
QString::fromStdString(it->host), it->port);
|
QString::fromStdString(it->host), it->port);
|
||||||
setupProxyCheck(prxy, url);
|
setupProxyCheck(prxy, url);
|
||||||
}
|
}
|
||||||
_timeout.start();
|
QNetworkProxy directProxy(QNetworkProxy::NoProxy);
|
||||||
|
setupProxyCheck(directProxy, url);
|
||||||
|
QNetworkProxy defaultProxy;
|
||||||
|
setupProxyCheck(defaultProxy, url);
|
||||||
|
_timeout2.start();
|
||||||
} else {
|
} else {
|
||||||
qDebug()<<"No proxy at all, giving up - offline?";
|
qDebug()<<"No proxy at all, giving up - offline?";
|
||||||
proxyError(QNetworkReply::TimeoutError);
|
proxyError(QNetworkReply::TimeoutError);
|
||||||
@@ -206,7 +216,8 @@ namespace proxy {
|
|||||||
qDebug()<<"Proxydetection got reply with status:"
|
qDebug()<<"Proxydetection got reply with status:"
|
||||||
<<reply->error()<<reply->errorString();
|
<<reply->error()<<reply->errorString();
|
||||||
if (reply->error()!=QNetworkReply::NoError) return; // wait for timeout
|
if (reply->error()!=QNetworkReply::NoError) return; // wait for timeout
|
||||||
_timeout.stop();
|
_timeout1.stop();
|
||||||
|
_timeout2.stop();
|
||||||
QNetworkProxy prxy(_requests[reply].second);
|
QNetworkProxy prxy(_requests[reply].second);
|
||||||
QUrl url(reply->url());
|
QUrl url(reply->url());
|
||||||
for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it)
|
for (Requests::iterator it(_requests.begin()); it!=_requests.end(); ++it)
|
||||||
@@ -222,7 +233,8 @@ namespace proxy {
|
|||||||
Requests;
|
Requests;
|
||||||
Requests _requests;
|
Requests _requests;
|
||||||
bool _direct;
|
bool _direct;
|
||||||
QTimer _timeout;
|
QTimer _timeout1;
|
||||||
|
QTimer _timeout2;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user