Skip to content

Commit

Permalink
Merge pull request #40628 from m-kuhn/timeout_disable
Browse files Browse the repository at this point in the history
Allow disabling QgsNetworkAccessManager timeout functionality
  • Loading branch information
m-kuhn committed Dec 17, 2020
2 parents 0d7b95f + 7388e67 commit c56d2d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions python/core/auto_generated/qgsnetworkaccessmanager.sip.in
Expand Up @@ -267,6 +267,7 @@ Returns the network timeout length, in milliseconds.
static void setTimeout( int time );
%Docstring
Sets the maximum timeout ``time`` for network requests, in milliseconds.
If set to 0, no timeout is set.

.. seealso:: :py:func:`timeout`

Expand Down
21 changes: 12 additions & 9 deletions src/core/qgsnetworkaccessmanager.cpp
Expand Up @@ -276,15 +276,18 @@ QNetworkReply *QgsNetworkAccessManager::createRequest( QNetworkAccessManager::Op
// The timer will call abortRequest slot to abort the connection if needed.
// The timer is stopped by the finished signal and is restarted on downloadProgress and
// uploadProgress.
QTimer *timer = new QTimer( reply );
timer->setObjectName( QStringLiteral( "timeoutTimer" ) );
connect( timer, &QTimer::timeout, this, &QgsNetworkAccessManager::abortRequest );
timer->setSingleShot( true );
timer->start( timeout() );

connect( reply, &QNetworkReply::downloadProgress, timer, [timer] { timer->start(); } );
connect( reply, &QNetworkReply::uploadProgress, timer, [timer] { timer->start(); } );
connect( reply, &QNetworkReply::finished, timer, &QTimer::stop );
if ( timeout() )
{
QTimer *timer = new QTimer( reply );
timer->setObjectName( QStringLiteral( "timeoutTimer" ) );
connect( timer, &QTimer::timeout, this, &QgsNetworkAccessManager::abortRequest );
timer->setSingleShot( true );
timer->start( timeout() );

connect( reply, &QNetworkReply::downloadProgress, timer, [timer] { timer->start(); } );
connect( reply, &QNetworkReply::uploadProgress, timer, [timer] { timer->start(); } );
connect( reply, &QNetworkReply::finished, timer, &QTimer::stop );
}
QgsDebugMsgLevel( QStringLiteral( "Created [reply:%1]" ).arg( reinterpret_cast< qint64 >( reply ), 0, 16 ), 3 );

return reply;
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsnetworkaccessmanager.h
Expand Up @@ -424,6 +424,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager

/**
* Sets the maximum timeout \a time for network requests, in milliseconds.
* If set to 0, no timeout is set.
*
* \see timeout()
* \since QGIS 3.6
Expand Down

0 comments on commit c56d2d8

Please sign in to comment.