merged integer overflow fix from RC_0_16

This commit is contained in:
Arvid Norberg 2014-04-16 08:25:14 +00:00
parent 2798c8d345
commit 0b3df1c973
2 changed files with 10 additions and 7 deletions

View File

@ -1123,10 +1123,10 @@ namespace libtorrent
// another peer sends us a have message for this piece
int m_superseed_piece[2];
// bytes downloaded since last second
// pieces downloaded since last second
// timer timeout; used for determining
// approx download rate
int m_remote_bytes_dled;
int m_remote_pieces_dled;
// approximate peer download rate
int m_remote_dl_rate;

View File

@ -175,7 +175,7 @@ namespace libtorrent
, m_download_limit(0)
, m_speed(slow)
, m_connection_ticket(-1)
, m_remote_bytes_dled(0)
, m_remote_pieces_dled(0)
, m_remote_dl_rate(0)
, m_outstanding_writing_bytes(0)
, m_download_rate_peak(0)
@ -1692,7 +1692,7 @@ namespace libtorrent
|| m_ses.session_time() - peer_info_struct()->last_connected > 2)
{
// update bytes downloaded since last timer
m_remote_bytes_dled += t->torrent_file().piece_size(index);
++m_remote_pieces_dled;
}
// it's important to not disconnect before we have
@ -4391,13 +4391,16 @@ namespace libtorrent
// update once every minute
if (now - m_remote_dl_update >= seconds(60))
{
boost::int64_t piece_size = t->torrent_file().piece_length();
if (m_remote_dl_rate > 0)
m_remote_dl_rate = (m_remote_dl_rate * 2 / 3) +
((m_remote_bytes_dled / 3) / 60);
((boost::int64_t(m_remote_pieces_dled) * piece_size / 3) / 60);
else
m_remote_dl_rate = m_remote_bytes_dled / 60;
m_remote_dl_rate = boost::int64_t(m_remote_pieces_dled)
* piece_size / 60;
m_remote_bytes_dled = 0;
m_remote_pieces_dled = 0;
m_remote_dl_update = now;
}