Discussion:
[libtorrent] state_update_alert
Michael Mckeown
2016-05-26 13:09:16 UTC
Permalink
Hi again, with state_update_alert I get 'state_update_alert state
updates for 0 torrents' with the vector of torrent_status having a count
of zero despite torrents running.

Pretty sure I'm doing it right:

session->post_torrent_updates ( );
session->pop_alerts ( &alerts );

for ( libtorrent::alert const* a : alerts ) {
if ( auto state = libtorrent::alert_cast<
libtorrent::state_update_alert >( a ) )
{
std::cout << "state_update_alert " << a->message ( ) << "\n";
for ( std::vector<torrent_status>::const_iterator it =
state->status.begin ( ) , end ( state->status.end ( ) ); it != end; ++it )
{
}
}
}

built with master from last night with:

toolset=msvc-14.0 boost-link=static runtime-link=static
deprecated-functions=off encryption=on link=static dht=on logging=off
i2p=on variant=release

Thanks.
Arvid Norberg
2016-05-26 17:27:08 UTC
Permalink
Post by Michael Mckeown
Hi again, with state_update_alert I get 'state_update_alert state
updates for 0 torrents' with the vector of torrent_status having a count
of zero despite torrents running.
The vector will be empty if no torrent has had any state changed. If
they're actively downloading, the upload and download byte counters count
as updated state and you should definitely get updates for them. But you
won't get updates unconditionally for every torrent.

Also keep in mind that it's possible to opt-out of the state update alerts.
If you clear the flag_update_subscribe in add_torrent_params, that torrent
will be excluded.

https://github.com/arvidn/libtorrent/blob/master/include/libtorrent/add_torrent_params.hpp#L222

you may have noticed that all examples touching the flags field of
add_torrent_params either bitwise OR-in a flag or bitwise AND-out a flag,
this is to preserve the other default flags, such as update_subscribe.
Post by Michael Mckeown
session->post_torrent_updates ( );
session->pop_alerts ( &alerts );
for ( libtorrent::alert const* a : alerts ) {
if ( auto state = libtorrent::alert_cast<
libtorrent::state_update_alert >( a ) )
{
std::cout << "state_update_alert " << a->message ( ) << "\n";
for ( std::vector<torrent_status>::const_iterator it =
state->status.begin ( ) , end ( state->status.end ( ) ); it != end; ++it )
{
}
}
}
toolset=msvc-14.0 boost-link=static runtime-link=static
deprecated-functions=off encryption=on link=static dht=on logging=off
i2p=on variant=release
--
Arvid Norberg
Michael Mckeown
2016-05-27 13:17:23 UTC
Permalink
bitwise was the problem, thanks.
Post by Arvid Norberg
Post by Michael Mckeown
Hi again, with state_update_alert I get 'state_update_alert state
updates for 0 torrents' with the vector of torrent_status having a count
of zero despite torrents running.
The vector will be empty if no torrent has had any state changed. If
they're actively downloading, the upload and download byte counters count
as updated state and you should definitely get updates for them. But you
won't get updates unconditionally for every torrent.
Also keep in mind that it's possible to opt-out of the state update alerts.
If you clear the flag_update_subscribe in add_torrent_params, that torrent
will be excluded.
https://github.com/arvidn/libtorrent/blob/master/include/libtorrent/add_torrent_params.hpp#L222
you may have noticed that all examples touching the flags field of
add_torrent_params either bitwise OR-in a flag or bitwise AND-out a flag,
this is to preserve the other default flags, such as update_subscribe.
Post by Michael Mckeown
session->post_torrent_updates ( );
session->pop_alerts ( &alerts );
for ( libtorrent::alert const* a : alerts ) {
if ( auto state = libtorrent::alert_cast<
libtorrent::state_update_alert >( a ) )
{
std::cout << "state_update_alert " << a->message ( ) << "\n";
for ( std::vector<torrent_status>::const_iterator it =
state->status.begin ( ) , end ( state->status.end ( ) ); it != end; ++it )
{
}
}
}
toolset=msvc-14.0 boost-link=static runtime-link=static
deprecated-functions=off encryption=on link=static dht=on logging=off
i2p=on variant=release
Continue reading on narkive:
Loading...