From 5aa348a5745c1336fb68e48b78567ce290224a92 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 20 Mar 2010 21:21:42 +0000 Subject: [PATCH] Save fast resume data every 3 minutes --- src/bittorrent.cpp | 23 +++++++++++++++++------ src/bittorrent.h | 3 +++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 5ebc7d531..48d855654 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -132,6 +131,8 @@ Bittorrent::Bittorrent() timerAlerts = new QTimer(); connect(timerAlerts, SIGNAL(timeout()), this, SLOT(readAlerts())); timerAlerts->start(3000); + connect(&resumeDataTimer, SIGNAL(timeout()), this, SLOT(saveTempFastResumeData())); + resumeDataTimer.start(180000); // 3min // To download from urls downloader = new downloadThread(this); connect(downloader, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); @@ -1393,10 +1394,23 @@ float Bittorrent::getRealRatio(QString hash) const{ return ratio; } +void Bittorrent::saveTempFastResumeData() { + std::vector torrents = s->get_torrents(); + std::vector::iterator torrentIT; + for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { + QTorrentHandle h = QTorrentHandle(*torrentIT); + if(!h.is_valid() || !h.has_metadata() || h.is_seed() || h.is_paused()) continue; + if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue; + qDebug("Saving fastresume data for %s", qPrintable(h.name())); + h.save_resume_data(); + } +} + // Only save fast resume data for unfinished and unpaused torrents (Optimization) // Called periodically and on exit void Bittorrent::saveFastResumeData() { // Stop listening for alerts + resumeDataTimer.stop(); timerAlerts->stop(); int num_resume_data = 0; // Pause session @@ -1985,12 +1999,9 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } } #endif - /*else if (torrent_paused_alert* p = dynamic_cast(a.get())) { - QTorrentHandle h(p->handle); - if(h.is_valid()) { - emit torrentPaused(h); + else if (torrent_paused_alert* p = dynamic_cast(a.get())) { + p->handle.save_resume_data(); } - }*/ else if (tracker_error_alert* p = dynamic_cast(a.get())) { // Level: fatal QTorrentHandle h(p->handle); diff --git a/src/bittorrent.h b/src/bittorrent.h index 9f88c5750..bb7175855 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -41,6 +41,7 @@ #include #endif #include +#include #include #include @@ -194,6 +195,7 @@ protected slots: void deleteBigRatios(); void takeETASamples(); void exportTorrentFiles(QString path); + void saveTempFastResumeData(); signals: void addedTorrent(QTorrentHandle& h); @@ -222,6 +224,7 @@ private: QMap savepath_fromurl; QHash > trackersInfos; QStringList torrentsToPausedAfterChecking; + QTimer resumeDataTimer; // Ratio QPointer BigRatioTimer; // HTTP