diff --git a/downloadthread.cpp b/downloadthread.cpp index 5a65800..979812b 100644 --- a/downloadthread.cpp +++ b/downloadthread.cpp @@ -339,6 +339,9 @@ void DownloadThread::run() curl_easy_setopt(_c, CURLOPT_FAILONERROR, 1); curl_easy_setopt(_c, CURLOPT_HEADERFUNCTION, &DownloadThread::_curl_header_callback); curl_easy_setopt(_c, CURLOPT_HEADERDATA, this); + curl_easy_setopt(_c, CURLOPT_CONNECTTIMEOUT, 30); + curl_easy_setopt(_c, CURLOPT_LOW_SPEED_TIME, 60); + curl_easy_setopt(_c, CURLOPT_LOW_SPEED_LIMIT, 100); if (_inputBufferSize) curl_easy_setopt(_c, CURLOPT_BUFFERSIZE, _inputBufferSize); @@ -352,8 +355,9 @@ void DownloadThread::run() CURLcode ret = curl_easy_perform(_c); /* Deal with badly configured HTTP servers that terminate the connection quickly - if connections stalls for some seconds while kernel commits buffers to slow SD card */ - while (ret == CURLE_PARTIAL_FILE) + if connections stalls for some seconds while kernel commits buffers to slow SD card. + And also reconnect if we detect from our end that transfer stalled for more than one minute */ + while (ret == CURLE_PARTIAL_FILE || ret == CURLE_OPERATION_TIMEDOUT) { time_t t = time(NULL); qDebug() << "HTTP connection lost. Time:" << t; @@ -602,6 +606,7 @@ void DownloadThread::_onDownloadSuccess() void DownloadThread::_onDownloadError(const QString &msg) { + _cancelled = true; emit error(msg); }