updated documentation on saving resume data and fixed client_test to do it properly
This commit is contained in:
parent
c04183d960
commit
18017c3f72
|
@ -2146,11 +2146,17 @@ The fast resume data will be empty in the following cases:
|
||||||
(see libtorrent's `metadata from peers`_ extension)
|
(see libtorrent's `metadata from peers`_ extension)
|
||||||
|
|
||||||
Note that by the time you receive the fast resume data, it may already be invalid if the torrent
|
Note that by the time you receive the fast resume data, it may already be invalid if the torrent
|
||||||
is still downloading! The recommended practice is to first pause the torrent, then generate the
|
is still downloading! The recommended practice is to first pause the session, then generate the
|
||||||
fast resume data, and then close it down. Make sure to not `remove_torrent()`_ before you receive
|
fast resume data, and then close it down. Make sure to not `remove_torrent()`_ before you receive
|
||||||
the `save_resume_data_alert`_ though. Only pause the torrent before you save the resume data
|
the `save_resume_data_alert`_ though. There's no need to pause when saving intermittent resume data.
|
||||||
if you will remove the torrent afterwards. There's no need to pause when saving intermittent
|
|
||||||
resume data.
|
.. warning:: If you pause every torrent individually instead of pausing the session, every torrent
|
||||||
|
will have its paused state saved in the resume data!
|
||||||
|
|
||||||
|
.. note:: It is typically a good idea to save resume data whenever a torrent is completed or paused. In those
|
||||||
|
cases you don't need to pause the torrent or the session, since the torrent will do no more writing
|
||||||
|
to its files. If you save resume data for torrents when they are paused, you can accelerate the
|
||||||
|
shutdown process by not saving resume data again for paused torrents.
|
||||||
|
|
||||||
In full allocation mode the reume data is never invalidated by subsequent
|
In full allocation mode the reume data is never invalidated by subsequent
|
||||||
writes to the files, since pieces won't move around. This means that you don't need to
|
writes to the files, since pieces won't move around. This means that you don't need to
|
||||||
|
@ -2168,13 +2174,14 @@ Example code to pause and save resume data for all torrents and wait for the ale
|
||||||
|
|
||||||
int num_resume_data = 0;
|
int num_resume_data = 0;
|
||||||
std::vector<torrent_handle> handles = ses.get_torrents();
|
std::vector<torrent_handle> handles = ses.get_torrents();
|
||||||
|
ses.pause();
|
||||||
for (std::vector<torrent_handle>::iterator i = handles.begin();
|
for (std::vector<torrent_handle>::iterator i = handles.begin();
|
||||||
i != handles.end(); ++i)
|
i != handles.end(); ++i)
|
||||||
{
|
{
|
||||||
torrent_handle& h = *i;
|
torrent_handle& h = *i;
|
||||||
if (!h.has_metadata()) continue;
|
if (!h.has_metadata()) continue;
|
||||||
|
if (!h.is_valid()) continue;
|
||||||
|
|
||||||
h.pause();
|
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
++num_resume_data;
|
++num_resume_data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1100,18 +1100,16 @@ int main(int ac, char* av[])
|
||||||
// keep track of the number of resume data
|
// keep track of the number of resume data
|
||||||
// alerts to wait for
|
// alerts to wait for
|
||||||
int num_resume_data = 0;
|
int num_resume_data = 0;
|
||||||
|
ses.pause();
|
||||||
for (handles_t::iterator i = handles.begin();
|
for (handles_t::iterator i = handles.begin();
|
||||||
i != handles.end(); ++i)
|
i != handles.end(); ++i)
|
||||||
{
|
{
|
||||||
torrent_handle& h = i->second;
|
torrent_handle& h = i->second;
|
||||||
if (!h.is_valid()) continue;
|
if (!h.is_valid()) continue;
|
||||||
h.auto_managed(false);
|
|
||||||
if (h.is_paused()) continue;
|
if (h.is_paused()) continue;
|
||||||
h.pause();
|
|
||||||
if (!h.has_metadata()) continue;
|
if (!h.has_metadata()) continue;
|
||||||
|
|
||||||
// pause
|
std::cout << "saving resume data for " << h.name() << std::endl;
|
||||||
std::cout << "pausing " << h.name() << std::endl;
|
|
||||||
// save_resume_data will generate an alert when it's done
|
// save_resume_data will generate an alert when it's done
|
||||||
h.save_resume_data();
|
h.save_resume_data();
|
||||||
++num_resume_data;
|
++num_resume_data;
|
||||||
|
|
Loading…
Reference in New Issue