Skip to content

Commit

Permalink
Update timeout of network request, if data is transferred
Browse files Browse the repository at this point in the history
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 d7c29ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/qgsnetworkaccessmanager.cpp
Expand Up @@ -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
Expand All @@ -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() );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsnetworkaccessmanager.h
Expand Up @@ -24,6 +24,8 @@
#include <QNetworkProxy>
#include <QNetworkRequest>

class QTimer;

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

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

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

QMap<QNetworkReply*, QTimer*> mActiveRequests;

static QgsNetworkAccessManager *smNAM;
};

Expand Down

0 comments on commit d7c29ae

Please sign in to comment.