Skip to content
Permalink
Browse files

Update timeout of network request, if data is transferred

Up to now, any network connection was killed after a max amount of
/qgis/networkAndProxy/networkTimeout milliseconds. This led to problems
for large or otherwise slow downloads.
This patch circumvents timeouts for as long as data is being
transferred.
  • Loading branch information
m-kuhn committed Oct 17, 2013
1 parent ddd4dae commit d7c29ae32b48b260dfb4cb60ffcb4b0818f191da
Showing with 27 additions and 0 deletions.
  1. +21 −0 src/core/qgsnetworkaccessmanager.cpp
  2. +6 −0 src/core/qgsnetworkaccessmanager.h
@@ -133,6 +133,9 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
{
emit requestAboutToBeCreated( op, req, outgoingData );
QNetworkReply *reply = QNetworkAccessManager::createRequest( op, req, outgoingData );
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( connectionProgress() ) );
connect( reply, SIGNAL( uploadProgress( qint64, qint64 ) ), this, SLOT( connectionProgress() ) );
connect( reply, SIGNAL( destroyed( QObject* ) ), this, SLOT( connectionDestroyed( QObject* ) ) );
emit requestCreated( reply );

// abort request, when network timeout happens
@@ -142,9 +145,27 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
timer->setSingleShot( true );
timer->start( s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt() );

mActiveRequests.insert( reply, timer );
return reply;
}

void QgsNetworkAccessManager::connectionProgress()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>( sender() );
Q_ASSERT( reply );

QTimer* timer = mActiveRequests.find( reply ).value();
Q_ASSERT( timer );

QSettings s;
timer->start( s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt() );
}

void QgsNetworkAccessManager::connectionDestroyed( QObject* reply )
{
mActiveRequests.remove( qobject_cast<QNetworkReply*>( reply ) );
}

void QgsNetworkAccessManager::abortRequest()
{
QTimer *timer = qobject_cast<QTimer *>( sender() );
@@ -24,6 +24,8 @@
#include <QNetworkProxy>
#include <QNetworkRequest>

class QTimer;

/*
* \class QgsNetworkAccessManager
* \brief network access manager for QGIS
@@ -84,6 +86,8 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
void requestCreated( QNetworkReply * );

private slots:
void connectionProgress();
void connectionDestroyed( QObject* );
void abortRequest();

protected:
@@ -97,6 +101,8 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
QNetworkProxy mFallbackProxy;
QStringList mExcludedURLs;

QMap<QNetworkReply*, QTimer*> mActiveRequests;

static QgsNetworkAccessManager *smNAM;
};

0 comments on commit d7c29ae

Please sign in to comment.
You can’t perform that action at this time.