pack members of pending_buffer a bit

This commit is contained in:
Arvid Norberg 2014-12-10 01:05:40 +00:00
parent 0b960615b1
commit 20b9a01a09
2 changed files with 21 additions and 12 deletions

View File

@ -107,20 +107,21 @@ namespace libtorrent
struct pending_block
{
pending_block(piece_block const& b)
: block(b), send_buffer_offset(-1), not_wanted(false)
: block(b), send_buffer_offset(not_in_buffer), not_wanted(false)
, timed_out(false), busy(false)
{}
piece_block block;
enum { not_in_buffer = 0x1fffffff };
// the number of bytes into the send buffer this request is. Every time
// some portion of the send buffer is transmitted, this offset is
// decremented by the number of bytes sent. once this drops below 0, the
// request_time field is set to the current time.
// if the request has not been written to the send buffer, this field
// remains -1.
// TODO: 3 make this 29 bits, to fit the bools in its tail
int send_buffer_offset;
// remains not_in_buffer.
boost::uint32_t send_buffer_offset:29;
// if any of these are set to true, this block
// is not allocated
@ -128,14 +129,14 @@ namespace libtorrent
// other peers to pick. This may be caused by
// it either timing out or being received
// unexpectedly from the peer
bool not_wanted:1;
bool timed_out:1;
boost::uint32_t not_wanted:1;
boost::uint32_t timed_out:1;
// the busy flag is set if the block was
// requested from another peer when this
// request was queued. We only allow a single
// busy request at a time in each peer's queue
bool busy:1;
boost::uint32_t busy:1;
bool operator==(pending_block const& b)
{

View File

@ -91,6 +91,11 @@ namespace libtorrent
min_request_queue = 2,
};
bool pending_block_in_buffer(pending_block const& pb)
{
return pb.send_buffer_offset != pending_block::not_in_buffer;
}
#if defined TORRENT_REQUEST_LOGGING
void write_request_log(FILE* f, sha1_hash const& ih
, peer_connection* p, peer_request const& r)
@ -4248,7 +4253,7 @@ namespace libtorrent
p.download_queue_length = int(download_queue().size() + m_request_queue.size());
p.requests_in_buffer = int(std::count_if(m_download_queue.begin()
, m_download_queue.end()
, boost::bind(&pending_block::send_buffer_offset, _1) >= 0));
, &pending_block_in_buffer));
p.target_dl_queue_length = int(desired_queue_size());
p.upload_queue_length = int(upload_queue().size());
@ -6193,10 +6198,13 @@ namespace libtorrent
for (std::vector<pending_block>::iterator i = m_download_queue.begin()
, end(m_download_queue.end()); i != end; ++i)
{
if (i->send_buffer_offset < 0) continue;
i->send_buffer_offset -= bytes_transferred;
if (i->send_buffer_offset >= 0) continue;
i->send_buffer_offset = -1;
if (i->send_buffer_offset == pending_block::not_in_buffer) continue;
boost::int32_t offset = i->send_buffer_offset;
offset -= bytes_transferred;
if (offset < 0)
i->send_buffer_offset = pending_block::not_in_buffer;
else
i->send_buffer_offset = offset;
}
m_channel_state[upload_channel] &= ~peer_info::bw_network;