start proxy detection in own thread
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QSslError>
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QDebug>
|
||||
#include <map>
|
||||
#endif
|
||||
@@ -76,7 +77,7 @@ namespace proxy {
|
||||
@example test.cxx */
|
||||
class Interface
|
||||
#ifdef QT_NETWORK_LIB
|
||||
: public QObject
|
||||
: public QThread
|
||||
#endif
|
||||
{
|
||||
#ifdef QT_NETWORK_LIB
|
||||
@@ -109,22 +110,12 @@ namespace proxy {
|
||||
@param timeout [ms] time to give up search */
|
||||
void proxy(const std::string& url,
|
||||
int timeout1=1000, int timeout2=30000) {
|
||||
qDebug()<<"Search proxy for URL, direct and default"
|
||||
<<"url="<<url.data()<<"timeout1="<<timeout1;
|
||||
for (Requests::iterator it(_requests.begin());
|
||||
it!=_requests.end(); ++it)
|
||||
delete it->second.first;
|
||||
_requests.clear();
|
||||
_direct = true; // first try direct access
|
||||
QNetworkProxy directProxy(QNetworkProxy::NoProxy);
|
||||
setupProxyCheck(directProxy, url);
|
||||
QNetworkProxy defaultProxy;
|
||||
setupProxyCheck(defaultProxy, url);
|
||||
_url = url;
|
||||
_timeout2.setSingleShot(true);
|
||||
_timeout2.setInterval(timeout2);
|
||||
_timeout1.setSingleShot(true);
|
||||
_timeout1.setInterval(timeout1);
|
||||
_timeout1.start();
|
||||
start(); // in own thread to prevent hanging at proxy request
|
||||
}
|
||||
//! If Qt Network is available you may check the proxies found
|
||||
/*! @copydoc proxy(const std::string&, int) */
|
||||
@@ -165,6 +156,23 @@ namespace proxy {
|
||||
void proxyFound(const QUrl&, const QNetworkProxy&);
|
||||
//! Signals a timeout, and no valid proxy for the URL requested earlier.
|
||||
void proxyError(QNetworkReply::NetworkError);
|
||||
protected:
|
||||
void run() {
|
||||
qDebug()<<"Search proxy for URL, direct and default"
|
||||
<<"url="<<_url.data();
|
||||
for (Requests::iterator it(_requests.begin());
|
||||
it!=_requests.end(); ++it)
|
||||
delete it->second.first;
|
||||
_requests.clear();
|
||||
_direct = true; // first try direct access
|
||||
QNetworkProxy directProxy(QNetworkProxy::NoProxy);
|
||||
setupProxyCheck(directProxy, _url);
|
||||
QNetworkProxy defaultProxy;
|
||||
setupProxyCheck(defaultProxy, _url);
|
||||
_timeout1.start();
|
||||
exec();
|
||||
}
|
||||
|
||||
private:
|
||||
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) {
|
||||
qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data();
|
||||
@@ -260,6 +268,7 @@ namespace proxy {
|
||||
bool _direct;
|
||||
QTimer _timeout1;
|
||||
QTimer _timeout2;
|
||||
std::string _url;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user