lt sync 2495

This commit is contained in:
Andrew Resch 2008-07-03 23:48:15 +00:00
commit bf70ff03a3
7 changed files with 73 additions and 17 deletions

View file

@ -275,4 +275,10 @@ void bind_alert()
class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>( class_<torrent_resumed_alert, bases<torrent_alert>, noncopyable>(
"torrent_resumed_alert", no_init "torrent_resumed_alert", no_init
); );
class_<state_changed_alert, bases<torrent_alert>, noncopyable>(
"state_changed_alert", no_init
)
.def_readonly("state", &state_changed_alert::state)
;
} }

View file

@ -68,6 +68,21 @@ namespace libtorrent
std::string name; std::string name;
}; };
struct TORRENT_EXPORT state_changed_alert: torrent_alert
{
state_changed_alert(torrent_handle const& h
, torrent_status::state_t const& state_
, std::string const& msg)
: torrent_alert(h, alert::info, msg)
, state(state_)
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new state_changed_alert(*this)); }
torrent_status::state_t state;
};
struct TORRENT_EXPORT tracker_alert: torrent_alert struct TORRENT_EXPORT tracker_alert: torrent_alert
{ {
tracker_alert(torrent_handle const& h tracker_alert(torrent_handle const& h

View file

@ -167,6 +167,7 @@ namespace libtorrent
bool is_aborted() const { return m_abort; } bool is_aborted() const { return m_abort; }
torrent_status::state_t state() const { return m_state; } torrent_status::state_t state() const { return m_state; }
void set_state(torrent_status::state_t s);
session_settings const& settings() const; session_settings const& settings() const;
@ -194,6 +195,7 @@ namespace libtorrent
void ip_filter_updated() { m_policy.ip_filter_updated(); } void ip_filter_updated() { m_policy.ip_filter_updated(); }
void set_error(std::string const& msg) { m_error = msg; }
bool has_error() const { return !m_error.empty(); } bool has_error() const { return !m_error.empty(); }
void pause(); void pause();
void resume(); void resume();

View file

@ -271,12 +271,16 @@ void http_connection::on_resolve(error_code const& e
std::transform(i, tcp::resolver::iterator(), std::back_inserter(m_endpoints) std::transform(i, tcp::resolver::iterator(), std::back_inserter(m_endpoints)
, boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1)); , boost::bind(&tcp::resolver::iterator::value_type::endpoint, _1));
// The following statement causes msvc to crash (ICE). Since it's not
// necessary in the vast majority of cases, just ignore the endpoint
// order for windows
#if !defined _MSC_VER || _MSC_VER > 1310
// sort the endpoints so that the ones with the same IP version as our // sort the endpoints so that the ones with the same IP version as our
// bound listen socket are first. So that when contacting a tracker, // bound listen socket are first. So that when contacting a tracker,
// we'll talk to it from the same IP that we're listening on // we'll talk to it from the same IP that we're listening on
m_endpoints.sort( std::partition(m_endpoints.begin(), m_endpoints.end()
(bind(&address::is_v4, bind(&tcp::endpoint::address, _1)) == m_bind_addr.is_v4()) , boost::bind(&address::is_v4, boost::bind(&tcp::endpoint::address, _1)) == m_bind_addr.is_v4());
> (bind(&address::is_v4, bind(&tcp::endpoint::address, _2)) == m_bind_addr.is_v4())); #endif
queue_connect(); queue_connect();
} }

View file

@ -35,6 +35,16 @@ POSSIBILITY OF SUCH DAMAGE.
#include <iomanip> #include <iomanip>
#include <cstring> #include <cstring>
namespace
{
enum
{
lazy_entry_grow_factor = 3,
lazy_entry_dict_init = 30,
lazy_entry_list_init = 50
};
}
namespace libtorrent namespace libtorrent
{ {
int fail_bdecode() { return -1; } int fail_bdecode() { return -1; }
@ -176,14 +186,14 @@ namespace libtorrent
TORRENT_ASSERT(m_size <= m_capacity); TORRENT_ASSERT(m_size <= m_capacity);
if (m_capacity == 0) if (m_capacity == 0)
{ {
int capacity = 10; int capacity = lazy_entry_dict_init;
m_data.dict = new (std::nothrow) std::pair<char const*, lazy_entry>[capacity]; m_data.dict = new (std::nothrow) std::pair<char const*, lazy_entry>[capacity];
if (m_data.dict == 0) return 0; if (m_data.dict == 0) return 0;
m_capacity = capacity; m_capacity = capacity;
} }
else if (m_size == m_capacity) else if (m_size == m_capacity)
{ {
int capacity = m_capacity * 2; int capacity = m_capacity * lazy_entry_grow_factor;
std::pair<char const*, lazy_entry>* tmp = new (std::nothrow) std::pair<char const*, lazy_entry>[capacity]; std::pair<char const*, lazy_entry>* tmp = new (std::nothrow) std::pair<char const*, lazy_entry>[capacity];
if (tmp == 0) return 0; if (tmp == 0) return 0;
std::memcpy(tmp, m_data.dict, sizeof(std::pair<char const*, lazy_entry>) * m_size); std::memcpy(tmp, m_data.dict, sizeof(std::pair<char const*, lazy_entry>) * m_size);
@ -289,14 +299,14 @@ namespace libtorrent
TORRENT_ASSERT(m_size <= m_capacity); TORRENT_ASSERT(m_size <= m_capacity);
if (m_capacity == 0) if (m_capacity == 0)
{ {
int capacity = 10; int capacity = lazy_entry_list_init;
m_data.list = new (std::nothrow) lazy_entry[capacity]; m_data.list = new (std::nothrow) lazy_entry[capacity];
if (m_data.list == 0) return 0; if (m_data.list == 0) return 0;
m_capacity = capacity; m_capacity = capacity;
} }
else if (m_size == m_capacity) else if (m_size == m_capacity)
{ {
int capacity = m_capacity * 2; int capacity = m_capacity * lazy_entry_grow_factor;
lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity]; lazy_entry* tmp = new (std::nothrow) lazy_entry[capacity];
if (tmp == 0) return 0; if (tmp == 0) return 0;
std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * m_size); std::memcpy(tmp, m_data.list, sizeof(lazy_entry) * m_size);

View file

@ -2847,6 +2847,7 @@ namespace libtorrent
{ {
t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str)); t->alerts().post_alert(file_error_alert(j.error_file, t->get_handle(), j.str));
} }
t->set_error(j.str);
t->pause(); t->pause();
return; return;
} }

View file

@ -446,7 +446,7 @@ namespace libtorrent
std::copy(url_seeds.begin(), url_seeds.end(), std::inserter(m_web_seeds std::copy(url_seeds.begin(), url_seeds.end(), std::inserter(m_web_seeds
, m_web_seeds.begin())); , m_web_seeds.begin()));
m_state = torrent_status::queued_for_checking; set_state(torrent_status::queued_for_checking);
if (m_resume_entry.type() == lazy_entry::dict_t) if (m_resume_entry.type() == lazy_entry::dict_t)
{ {
@ -474,7 +474,7 @@ namespace libtorrent
if (error) if (error)
{ {
std::vector<char>().swap(m_resume_data); std::vector<char>().swap(m_resume_data);
m_resume_entry = lazy_entry(); lazy_entry().swap(m_resume_entry);
} }
else else
{ {
@ -505,6 +505,10 @@ namespace libtorrent
} }
m_error = j.str; m_error = j.str;
pause(); pause();
std::vector<char>().swap(m_resume_data);
lazy_entry().swap(m_resume_entry);
return; return;
} }
@ -627,6 +631,9 @@ namespace libtorrent
// some files // some files
m_ses.check_torrent(shared_from_this()); m_ses.check_torrent(shared_from_this());
} }
std::vector<char>().swap(m_resume_data);
lazy_entry().swap(m_resume_entry);
} }
void torrent::force_recheck() void torrent::force_recheck()
@ -647,13 +654,13 @@ namespace libtorrent
, int((m_torrent_file->total_size()+m_block_size-1)/m_block_size)); , int((m_torrent_file->total_size()+m_block_size-1)/m_block_size));
// assume that we don't have anything // assume that we don't have anything
m_files_checked = false; m_files_checked = false;
m_state = torrent_status::queued_for_checking; set_state(torrent_status::queued_for_checking);
if (m_auto_managed) if (m_auto_managed)
set_queue_position((std::numeric_limits<int>::max)()); set_queue_position((std::numeric_limits<int>::max)());
std::vector<char>().swap(m_resume_data); std::vector<char>().swap(m_resume_data);
m_resume_entry = lazy_entry(); lazy_entry().swap(m_resume_entry);
m_storage->async_check_fastresume(&m_resume_entry m_storage->async_check_fastresume(&m_resume_entry
, bind(&torrent::on_force_recheck , bind(&torrent::on_force_recheck
, shared_from_this(), _1, _2)); , shared_from_this(), _1, _2));
@ -684,7 +691,7 @@ namespace libtorrent
void torrent::start_checking() void torrent::start_checking()
{ {
m_state = torrent_status::checking_files; set_state(torrent_status::checking_files);
m_storage->async_check_files(bind( m_storage->async_check_files(bind(
&torrent::on_piece_checked &torrent::on_piece_checked
@ -3054,7 +3061,7 @@ namespace libtorrent
, "torrent has finished downloading")); , "torrent has finished downloading"));
} }
m_state = torrent_status::finished; set_state(torrent_status::finished);
set_queue_position(-1); set_queue_position(-1);
// we have to call completed() before we start // we have to call completed() before we start
@ -3095,7 +3102,7 @@ namespace libtorrent
INVARIANT_CHECK; INVARIANT_CHECK;
TORRENT_ASSERT(!is_finished()); TORRENT_ASSERT(!is_finished());
m_state = torrent_status::downloading; set_state(torrent_status::downloading);
set_queue_position((std::numeric_limits<int>::max)()); set_queue_position((std::numeric_limits<int>::max)());
} }
@ -3109,7 +3116,7 @@ namespace libtorrent
// make the next tracker request // make the next tracker request
// be a completed-event // be a completed-event
m_event = tracker_request::completed; m_event = tracker_request::completed;
m_state = torrent_status::seeding; set_state(torrent_status::seeding);
force_tracker_request(); force_tracker_request();
} }
@ -3181,7 +3188,7 @@ namespace libtorrent
TORRENT_ASSERT(m_torrent_file->is_valid()); TORRENT_ASSERT(m_torrent_file->is_valid());
INVARIANT_CHECK; INVARIANT_CHECK;
m_state = torrent_status::connecting_to_tracker; set_state(torrent_status::connecting_to_tracker);
if (!is_seed()) if (!is_seed())
{ {
@ -4032,6 +4039,17 @@ namespace libtorrent
} }
} }
void torrent::set_state(torrent_status::state_t s)
{
if (m_state == s) return;
m_state = s;
if (m_ses.m_alerts.should_post(alert::info))
{
m_ses.m_alerts.post_alert(state_changed_alert(get_handle()
, s, "torrent status changed"));
}
}
torrent_status torrent::status() const torrent_status torrent::status() const
{ {
INVARIANT_CHECK; INVARIANT_CHECK;