start proxy detection in own thread

master
Marc Wäckerlin 15 years ago
parent a563d8995a
commit 75b09d79e7
  1. 2
      COPYING
  2. 2
      INSTALL
  3. 35
      proxyface/autoproxy.hxx

@ -1 +1 @@
/usr/share/automake-1.10/COPYING /usr/share/automake-1.11/COPYING

@ -1 +1 @@
/usr/share/automake-1.10/INSTALL /usr/share/automake-1.11/INSTALL

@ -14,6 +14,7 @@
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QtNetwork/QSslError> #include <QtNetwork/QSslError>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QThread>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <map> #include <map>
#endif #endif
@ -76,7 +77,7 @@ namespace proxy {
@example test.cxx */ @example test.cxx */
class Interface class Interface
#ifdef QT_NETWORK_LIB #ifdef QT_NETWORK_LIB
: public QObject : public QThread
#endif #endif
{ {
#ifdef QT_NETWORK_LIB #ifdef QT_NETWORK_LIB
@ -109,22 +110,12 @@ namespace proxy {
@param timeout [ms] time to give up search */ @param timeout [ms] time to give up search */
void proxy(const std::string& url, void proxy(const std::string& url,
int timeout1=1000, int timeout2=30000) { int timeout1=1000, int timeout2=30000) {
qDebug()<<"Search proxy for URL, direct and default" _url = url;
<<"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);
_timeout2.setSingleShot(true); _timeout2.setSingleShot(true);
_timeout2.setInterval(timeout2); _timeout2.setInterval(timeout2);
_timeout1.setSingleShot(true); _timeout1.setSingleShot(true);
_timeout1.setInterval(timeout1); _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 //! If Qt Network is available you may check the proxies found
/*! @copydoc proxy(const std::string&, int) */ /*! @copydoc proxy(const std::string&, int) */
@ -165,6 +156,23 @@ namespace proxy {
void proxyFound(const QUrl&, const QNetworkProxy&); void proxyFound(const QUrl&, const QNetworkProxy&);
//! Signals a timeout, and no valid proxy for the URL requested earlier. //! Signals a timeout, and no valid proxy for the URL requested earlier.
void proxyError(QNetworkReply::NetworkError); 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: private:
void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) { void setupProxyCheck(const QNetworkProxy& prxy, const std::string& url) {
qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data(); qDebug()<<"Testing proxy for url:"<<toString(prxy)<<"url="<<url.data();
@ -260,6 +268,7 @@ namespace proxy {
bool _direct; bool _direct;
QTimer _timeout1; QTimer _timeout1;
QTimer _timeout2; QTimer _timeout2;
std::string _url;
#endif #endif
}; };
} }

Loading…
Cancel
Save