send buffer heap optimization

This commit is contained in:
Arvid Norberg 2007-05-10 06:20:29 +00:00
parent e6c7945aac
commit 57439bcec8
1 changed files with 11 additions and 4 deletions

View File

@ -1855,8 +1855,15 @@ namespace libtorrent
// only add new piece-chunks if the send buffer is small enough // only add new piece-chunks if the send buffer is small enough
// otherwise there will be no end to how large it will be! // otherwise there will be no end to how large it will be!
// TODO: the buffer size should probably be dependent on the transfer speed // TODO: the buffer size should probably be dependent on the transfer speed
int blocks_per_second = m_statistics.upload_rate() / t->block_size();
if (blocks_per_second == 0) blocks_per_second = 1;
else if (blocks_per_second > 12) blocks_per_second = 12;
int buffer_size_watermark = t->block_size() * blocks_per_second / 2;
while (!m_requests.empty() while (!m_requests.empty()
&& (send_buffer_size() < t->block_size() * 6) && (send_buffer_size() < buffer_size_watermark)
&& !m_choked) && !m_choked)
{ {
assert(t->valid_metadata()); assert(t->valid_metadata());