Skip to content
Permalink
Browse files

Allow disabling QgsNetworkAccessManager timeout functionality

by setting the timout to 0

This can be interesting to overcome the limitations of the timeout
functionality by replacing it with QNetworkAccessManager::setTransferTimeout.
E.g. to have more than 6 downloads running in parallel.
  • Loading branch information
m-kuhn committed Dec 16, 2020
1 parent 9763773 commit 7388e67bd0c70f3ba82a47c60acdbe9344afde03
@@ -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 7388e67

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