Skip to content
Permalink
Browse files

Merge pull request #40628 from m-kuhn/timeout_disable

Allow disabling QgsNetworkAccessManager timeout functionality
  • Loading branch information
m-kuhn committed Dec 17, 2020
2 parents 0d7b95f + 7388e67 commit c56d2d8d885c958ed56f8ead297e7928596269f7
@@ -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`

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

0 comments on commit c56d2d8

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