Skip to content

Commit

Permalink
[wfs] Respect request timeout when retrieving features
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 18, 2018
1 parent 48f166e commit 7e24ec6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Expand Up @@ -1111,6 +1111,14 @@ void QgsWFSFeatureIterator::checkInterruption()
}
}

void QgsWFSFeatureIterator::timeout()
{
mTimeoutOccurred = true;
mDownloadFinished = true;
if ( mLoop )
mLoop->quit();
}

bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
{
f.setValid( false );
Expand All @@ -1125,6 +1133,9 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
if ( mInterruptionChecker && mInterruptionChecker->isCanceled() )
return false;

if ( mTimeoutOccurred )
return false;

//QgsDebugMsg(QString("QgsWFSSharedData::fetchFeature() : mCacheIterator.nextFeature(cachedFeature)") );

if ( !mShared->mGeometryAttribute.isEmpty() && mFetchGeometry )
Expand Down Expand Up @@ -1279,6 +1290,12 @@ bool QgsWFSFeatureIterator::fetchFeature( QgsFeature &f )
mLoop = &loop;
QTimer timer( this );
timer.start( 50 );
QTimer requestTimeout( this );
if ( mRequest.connectionTimeout() > 0 )
{
connect( &requestTimeout, &QTimer::timeout, this, &QgsWFSFeatureIterator::timeout );
requestTimeout.start( mRequest.connectionTimeout() );
}
if ( mInterruptionChecker )
connect( &timer, &QTimer::timeout, this, &QgsWFSFeatureIterator::checkInterruption );
loop.exec( QEventLoop::ExcludeUserInputEvents );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wfs/qgswfsfeatureiterator.h
Expand Up @@ -217,6 +217,7 @@ class QgsWFSFeatureIterator : public QObject,
void featureReceivedSynchronous( const QVector<QgsWFSFeatureGmlIdPair> &list );
void endOfDownload( bool success );
void checkInterruption();
void timeout();

private:

Expand All @@ -237,6 +238,7 @@ class QgsWFSFeatureIterator : public QObject,
QEventLoop *mLoop = nullptr;
QgsFeatureIterator mCacheIterator;
QgsFeedback *mInterruptionChecker = nullptr;
bool mTimeoutOccurred = false;

//! this mutex synchronizes the mWriterXXXX variables between featureReceivedSynchronous() and fetchFeature()
QMutex mMutex;
Expand Down

0 comments on commit 7e24ec6

Please sign in to comment.