make receive_buffer() not return a range exceeding the actual buffer

This commit is contained in:
Arvid Norberg 2011-11-27 01:08:28 +00:00
parent c3695d9fbb
commit f979f7a77b
2 changed files with 7 additions and 5 deletions

View File

@ -590,6 +590,8 @@ namespace libtorrent
bool packet_finished() const
{ return m_packet_size <= m_recv_pos; }
int receive_pos() const { return m_recv_pos; }
#ifdef TORRENT_DEBUG
bool piece_failed;
#endif
@ -649,9 +651,9 @@ namespace libtorrent
{
TORRENT_ASSERT(!m_disk_recv_buffer);
TORRENT_ASSERT(m_disk_recv_buffer_size == 0);
if (m_recv_buffer.empty()) return buffer::interval(0,0);
int rcv_pos = (std::min)(m_recv_pos, int(m_recv_buffer.size()));
return buffer::interval(&m_recv_buffer[0]
, &m_recv_buffer[0] + m_recv_pos);
, &m_recv_buffer[0] + rcv_pos);
}
std::pair<buffer::interval, buffer::interval> wr_recv_buffers(int bytes);
@ -659,9 +661,9 @@ namespace libtorrent
buffer::const_interval receive_buffer() const
{
if (m_recv_buffer.empty()) return buffer::const_interval(0,0);
int rcv_pos = (std::min)(m_recv_pos, int(m_recv_buffer.size()));
return buffer::const_interval(&m_recv_buffer[0]
, &m_recv_buffer[0] + m_recv_pos);
, &m_recv_buffer[0] + rcv_pos);
}
bool allocate_disk_receive_buffer(int disk_buffer_size);

View File

@ -1082,7 +1082,7 @@ namespace libtorrent
TORRENT_ASSERT(received > 0);
buffer::const_interval recv_buffer = receive_buffer();
int recv_pos = recv_buffer.end - recv_buffer.begin;
int recv_pos = receive_pos(); // recv_buffer.end - recv_buffer.begin;
boost::shared_ptr<torrent> t = associated_torrent().lock();
TORRENT_ASSERT(t);