RTorrent Patch
From KdjWiki
Patching rTorrent
I liked rTorrent but wanted to have it auto exit when it completed downloading a torrent (so I could use it in my daily cron job which downloads podcasts). In order to to this, I had make the following modifications and recompile:
src/main.cc
Change:
int main(int argc, char** argv)
{
...
while (!uiControl.is_shutdown_completed())
{
utils::Timer::update();
utils::taskScheduler.execute(utils::Timer::cache());
// This needs to be called every second or so. Currently done by the throttle task in libtorrent.
if (!utils::displayScheduler.empty() && utils::displayScheduler.get_next_timeout() <= utils::Timer::cache())
{
uiControl.display()->do_update();
}
// Do shutdown check before poll, not after.
uiControl.core()->get_poll_manager()->poll(!utils::taskScheduler.empty() ? utils::taskScheduler.get_next_timeout() - utils::Timer::cache() : 60 * 1000000);
}
...
}
To:
int main(int argc, char** argv)
{
...
while (!uiControl.is_shutdown_completed())
{
utils::Timer::update();
utils::taskScheduler.execute(utils::Timer::cache());
// This needs to be called every second or so. Currently done by the throttle task in libtorrent.
if (!utils::displayScheduler.empty() && utils::displayScheduler.get_next_timeout() <= utils::Timer::cache())
{
uiControl.display()->do_update();
}
core::DownloadList* list = &uiControl.core()->get_download_list();
if (list->empty())
{
// No torrents in list - exit
uiControl.receive_shutdown();
}
else
{
bool more = false;
std::list<core::Download *>::iterator d = list->begin();
do
{
core::Download* dl = *d;
if (!dl->is_done())
{
more = true;
}
}
while (++d != list->end());
if (!more)
{
// All done - exit
uiControl.receive_shutdown();
}
}
// Do shutdown check before poll, not after.
uiControl.core()->get_poll_manager()->poll(!utils::taskScheduler.empty() ? utils::taskScheduler.get_next_timeout() - utils::Timer::cache() : 60 * 1000000);
}
...
}