From 51db83b9d25e4f4f5fcc2870b136c61d43d1167f Mon Sep 17 00:00:00 2001 From: Max Lapan Date: Fri, 19 Mar 2010 14:43:31 +0300 Subject: [PATCH] Abort current connection (if any) with new request. --- http_fetcher.cpp | 17 +++-------------- http_fetcher.hpp | 2 -- traffic.cpp | 13 ------------- traffic.hpp | 3 --- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/http_fetcher.cpp b/http_fetcher.cpp index 543260d..433c990 100644 --- a/http_fetcher.cpp +++ b/http_fetcher.cpp @@ -13,16 +13,13 @@ HttpFetcher::HttpFetcher () } -bool HttpFetcher::busy () const -{ - return _http.currentId () != 0; -} - - void HttpFetcher::fetch (const QString& url) { QUrl u (url); + if (_http.currentId () != ) + _http.abort (); + if (u.isValid ()) { _http.setHost (u.host ()); _http.get (u.encodedPath (), &_buffer); @@ -40,11 +37,3 @@ void HttpFetcher::requestDone (bool err) _buffer.setBuffer (NULL); } - -void HttpFetcher::reset () -{ - if (!busy ()) - return; - - _http.abort (); -} diff --git a/http_fetcher.hpp b/http_fetcher.hpp index 416d62f..25857bb 100644 --- a/http_fetcher.hpp +++ b/http_fetcher.hpp @@ -22,9 +22,7 @@ signals: public: HttpFetcher (); - bool busy () const; void fetch (const QString& url); - void reset (); }; diff --git a/traffic.cpp b/traffic.cpp index 3cc7097..05d5adf 100644 --- a/traffic.cpp +++ b/traffic.cpp @@ -3,7 +3,6 @@ #include "traffic.hpp" #include "log.hpp" -#include "connection.hpp" // -------------------------------------------------- @@ -133,7 +132,6 @@ Traffic::Traffic () { connect (&_fetcher, SIGNAL (done (const QByteArray&)), SLOT (fetchDone (const QByteArray&))); - connect (ConnectionChecker::instance (), SIGNAL (connected (bool)), SLOT (connectionChanged (bool))); } @@ -142,11 +140,6 @@ Traffic::Traffic () // successfully, updated() signal called. void Traffic::update () { - if (_fetcher.busy ()) { - Log::instance ()->add ("Traffic::update: fetcher is busy"); - return; - } - Log::instance ()->add ("Traffic::update: Request status download"); _fetcher.fetch ("http://trf.maps.yandex.net/trf/stat.xml"); } @@ -245,9 +238,3 @@ ExtendedTrafficInfo Traffic::lookup_ext (const QString &id) const return it.value (); } - -void Traffic::connectionChanged (bool active) -{ - if (!active) - _fetcher.reset (); -} diff --git a/traffic.hpp b/traffic.hpp index 4ec08e4..03283b8 100644 --- a/traffic.hpp +++ b/traffic.hpp @@ -105,9 +105,6 @@ private: private slots: void fetchDone (const QByteArray& data); -protected slots: - void connectionChanged (bool active); - signals: void updated (); -- 1.7.9.5