From 75b09d79e70642ae37b4c6dcc8622a1020d69253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Tue, 3 Nov 2009 09:56:38 +0000 Subject: [PATCH] start proxy detection in own thread --- COPYING | 2 +- INSTALL | 2 +- proxyface/autoproxy.hxx | 35 ++++++++++++++++++++++------------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/COPYING b/COPYING index 0b6cbf8..6168a39 120000 --- a/COPYING +++ b/COPYING @@ -1 +1 @@ -/usr/share/automake-1.10/COPYING \ No newline at end of file +/usr/share/automake-1.11/COPYING \ No newline at end of file diff --git a/INSTALL b/INSTALL index 5bb6e7b..cbd1c80 120000 --- a/INSTALL +++ b/INSTALL @@ -1 +1 @@ -/usr/share/automake-1.10/INSTALL \ No newline at end of file +/usr/share/automake-1.11/INSTALL \ No newline at end of file diff --git a/proxyface/autoproxy.hxx b/proxyface/autoproxy.hxx index c6551c2..8d562bc 100644 --- a/proxyface/autoproxy.hxx +++ b/proxyface/autoproxy.hxx @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #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="<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:"<