Skip to content
Permalink
Browse files

[wfs] Respect request timeout when retrieving features

  • Loading branch information
nyalldawson committed Aug 6, 2018
1 parent 48f166e commit 7e24ec686ab92305af2dd0976770172541a06ef2
Showing with 19 additions and 0 deletions.
  1. +17 −0 src/providers/wfs/qgswfsfeatureiterator.cpp
  2. +2 −0 src/providers/wfs/qgswfsfeatureiterator.h
@@ -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 );
@@ -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 )
@@ -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 );
@@ -217,6 +217,7 @@ class QgsWFSFeatureIterator : public QObject,
void featureReceivedSynchronous( const QVector<QgsWFSFeatureGmlIdPair> &list );
void endOfDownload( bool success );
void checkInterruption();
void timeout();

private:

@@ -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;

0 comments on commit 7e24ec6

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