Skip to content

Commit d1dffdc

Browse files
committed
Merge pull request #1314 from manisandro/network_timeout
Restart timeout timer when data is received in QgsNetworkAccessManager
2 parents a1f1b94 + d2dce59 commit d1dffdc

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/app/qgisapp.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -9301,6 +9301,8 @@ void QgisApp::namSetup()
93019301
connect( nam, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
93029302
this, SLOT( namProxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ) );
93039303

9304+
connect( nam, SIGNAL( requestTimedOut( QNetworkReply* ) ), this, SLOT( namRequestTimedOut( QNetworkReply* ) ) );
9305+
93049306
#ifndef QT_NO_OPENSSL
93059307
connect( nam, SIGNAL( sslErrors( QNetworkReply *, const QList<QSslError> & ) ),
93069308
this, SLOT( namSslErrors( QNetworkReply *, const QList<QSslError> & ) ) );
@@ -9386,6 +9388,12 @@ void QgisApp::namSslErrors( QNetworkReply *reply, const QList<QSslError> &errors
93869388
}
93879389
#endif
93889390

9391+
void QgisApp::namRequestTimedOut( QNetworkReply *reply )
9392+
{
9393+
QgsMessageLog::logMessage( tr( "The request '%1' timed out. Any data received is likely incomplete." ).arg( reply->url().toString() ), QString::null, QgsMessageLog::WARNING );
9394+
messageBar()->pushMessage( tr( "Network request timeout" ), tr( "A network request timed out, any data received is likely incomplete." ), QgsMessageBar::WARNING, messageTimeout() );
9395+
}
9396+
93899397
void QgisApp::namUpdate()
93909398
{
93919399
QgsNetworkAccessManager::instance()->setupDefaultProxyAndCache();

src/app/qgisapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
594594
#ifndef QT_NO_OPENSSL
595595
void namSslErrors( QNetworkReply *reply, const QList<QSslError> &errors );
596596
#endif
597+
void namRequestTimedOut( QNetworkReply *reply );
597598

598599
//! update default action of toolbutton
599600
void toolButtonActionTriggered( QAction * );
@@ -1553,3 +1554,4 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
15531554
#endif
15541555

15551556
#endif
1557+

src/core/qgsnetworkaccessmanager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
161161
timer->setSingleShot( true );
162162
timer->start( s.value( "/qgis/networkAndProxy/networkTimeout", "20000" ).toInt() );
163163

164+
connect( reply, SIGNAL( downloadProgress( qint64, qint64 ) ), timer, SLOT( start() ) );
165+
164166
mActiveRequests.insert( reply, timer );
165167
return reply;
166168
}
@@ -194,6 +196,8 @@ void QgsNetworkAccessManager::abortRequest()
194196

195197
if ( reply->isRunning() )
196198
reply->close();
199+
200+
emit requestTimedOut( reply );
197201
}
198202

199203
QString QgsNetworkAccessManager::cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl )
@@ -324,3 +328,4 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
324328
setProxy( proxy );
325329
#endif
326330
}
331+

src/core/qgsnetworkaccessmanager.h

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
8787
signals:
8888
void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * );
8989
void requestCreated( QNetworkReply * );
90+
void requestTimedOut( QNetworkReply * );
9091

9192
private slots:
9293
void connectionProgress();
@@ -105,3 +106,4 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
105106
};
106107

107108
#endif // QGSNETWORKACCESSMANAGER_H
109+

0 commit comments

Comments
 (0)