pack members of pending_buffer a bit
This commit is contained in:
parent
0b960615b1
commit
20b9a01a09
|
@ -107,20 +107,21 @@ namespace libtorrent
|
||||||
struct pending_block
|
struct pending_block
|
||||||
{
|
{
|
||||||
pending_block(piece_block const& b)
|
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)
|
, timed_out(false), busy(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
piece_block block;
|
piece_block block;
|
||||||
|
|
||||||
|
enum { not_in_buffer = 0x1fffffff };
|
||||||
|
|
||||||
// the number of bytes into the send buffer this request is. Every time
|
// the number of bytes into the send buffer this request is. Every time
|
||||||
// some portion of the send buffer is transmitted, this offset is
|
// some portion of the send buffer is transmitted, this offset is
|
||||||
// decremented by the number of bytes sent. once this drops below 0, the
|
// decremented by the number of bytes sent. once this drops below 0, the
|
||||||
// request_time field is set to the current time.
|
// request_time field is set to the current time.
|
||||||
// if the request has not been written to the send buffer, this field
|
// if the request has not been written to the send buffer, this field
|
||||||
// remains -1.
|
// remains not_in_buffer.
|
||||||
// TODO: 3 make this 29 bits, to fit the bools in its tail
|
boost::uint32_t send_buffer_offset:29;
|
||||||
int send_buffer_offset;
|
|
||||||
|
|
||||||
// if any of these are set to true, this block
|
// if any of these are set to true, this block
|
||||||
// is not allocated
|
// is not allocated
|
||||||
|
@ -128,14 +129,14 @@ namespace libtorrent
|
||||||
// other peers to pick. This may be caused by
|
// other peers to pick. This may be caused by
|
||||||
// it either timing out or being received
|
// it either timing out or being received
|
||||||
// unexpectedly from the peer
|
// unexpectedly from the peer
|
||||||
bool not_wanted:1;
|
boost::uint32_t not_wanted:1;
|
||||||
bool timed_out:1;
|
boost::uint32_t timed_out:1;
|
||||||
|
|
||||||
// the busy flag is set if the block was
|
// the busy flag is set if the block was
|
||||||
// requested from another peer when this
|
// requested from another peer when this
|
||||||
// request was queued. We only allow a single
|
// request was queued. We only allow a single
|
||||||
// busy request at a time in each peer's queue
|
// busy request at a time in each peer's queue
|
||||||
bool busy:1;
|
boost::uint32_t busy:1;
|
||||||
|
|
||||||
bool operator==(pending_block const& b)
|
bool operator==(pending_block const& b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,6 +91,11 @@ namespace libtorrent
|
||||||
min_request_queue = 2,
|
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
|
#if defined TORRENT_REQUEST_LOGGING
|
||||||
void write_request_log(FILE* f, sha1_hash const& ih
|
void write_request_log(FILE* f, sha1_hash const& ih
|
||||||
, peer_connection* p, peer_request const& r)
|
, 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.download_queue_length = int(download_queue().size() + m_request_queue.size());
|
||||||
p.requests_in_buffer = int(std::count_if(m_download_queue.begin()
|
p.requests_in_buffer = int(std::count_if(m_download_queue.begin()
|
||||||
, m_download_queue.end()
|
, 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.target_dl_queue_length = int(desired_queue_size());
|
||||||
p.upload_queue_length = int(upload_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()
|
for (std::vector<pending_block>::iterator i = m_download_queue.begin()
|
||||||
, end(m_download_queue.end()); i != end; ++i)
|
, end(m_download_queue.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
if (i->send_buffer_offset < 0) continue;
|
if (i->send_buffer_offset == pending_block::not_in_buffer) continue;
|
||||||
i->send_buffer_offset -= bytes_transferred;
|
boost::int32_t offset = i->send_buffer_offset;
|
||||||
if (i->send_buffer_offset >= 0) continue;
|
offset -= bytes_transferred;
|
||||||
i->send_buffer_offset = -1;
|
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;
|
m_channel_state[upload_channel] &= ~peer_info::bw_network;
|
||||||
|
|
Loading…
Reference in New Issue