diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 46fc87964..70a02c888 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -240,6 +240,9 @@ namespace aux { http_seed }; + struct request_flags_tag; + using request_flags_t = flags::bitfield_flag; + class TORRENT_EXTRA_EXPORT peer_connection : public peer_connection_hot_members , public bandwidth_socket @@ -584,10 +587,12 @@ namespace aux { // if the block was already time-critical, it returns false. bool make_time_critical(piece_block const& block); + static constexpr request_flags_t time_critical{1}; + static constexpr request_flags_t busy{2}; + // adds a block to the request queue // returns true if successful, false otherwise - enum flags_t { req_time_critical = 1, req_busy = 2 }; - bool add_request(piece_block const& b, int flags = 0); + bool add_request(piece_block const& b, request_flags_t flags = {}); // clears the request queue and sends cancels for all messages // in the download queue diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 11de30242..ff3b35433 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -86,6 +86,9 @@ using namespace std::placeholders; namespace libtorrent { + constexpr request_flags_t peer_connection::time_critical; + constexpr request_flags_t peer_connection::busy; + namespace { // the limits of the download queue size @@ -3405,7 +3408,8 @@ namespace libtorrent { return true; } - bool peer_connection::add_request(piece_block const& block, int const flags) + bool peer_connection::add_request(piece_block const& block + , request_flags_t const flags) { TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; @@ -3446,7 +3450,7 @@ namespace libtorrent { return false; } - if ((flags & req_busy) && !(flags & req_time_critical)) + if ((flags & busy) && !(flags & time_critical)) { // this block is busy (i.e. it has been requested // from another peer already). Only allow one busy @@ -3495,8 +3499,8 @@ namespace libtorrent { } pending_block pb(block); - pb.busy = (flags & req_busy) ? true : false; - if (flags & req_time_critical) + pb.busy = (flags & busy) ? true : false; + if (flags & time_critical) { m_request_queue.insert(m_request_queue.begin() + m_queued_time_critical , pb); diff --git a/src/request_blocks.cpp b/src/request_blocks.cpp index 324ca3a02..c6c27e0af 100644 --- a/src/request_blocks.cpp +++ b/src/request_blocks.cpp @@ -252,7 +252,7 @@ namespace libtorrent { // ok, we found a piece that's not being downloaded // by somebody else. request it from this peer // and return - if (!c.add_request(*i, 0)) continue; + if (!c.add_request(*i, {})) continue; TORRENT_ASSERT(p.num_peers(*i) == 1); TORRENT_ASSERT(p.is_requested(*i)); num_requests--; @@ -298,7 +298,7 @@ namespace libtorrent { TORRENT_ASSERT(!p.is_finished(busy_block)); TORRENT_ASSERT(p.num_peers(busy_block) > 0); - c.add_request(busy_block, peer_connection::req_busy); + c.add_request(busy_block, peer_connection::busy); return true; } diff --git a/src/torrent.cpp b/src/torrent.cpp index d54f547df..33d90b6cd 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -9643,8 +9643,8 @@ namespace libtorrent { } else { - if (!c.add_request(b, peer_connection::req_time_critical - | (busy_mode ? peer_connection::req_busy : 0))) + if (!c.add_request(b, peer_connection::time_critical + | (busy_mode ? peer_connection::busy : request_flags_t{}))) { #if TORRENT_DEBUG_STREAMING > 1 std::printf("failed to request block [%d, %d]\n"