Modernize bandwidth.cc: Moved functions inside struct (#1895)

* Modernize bandwidth.cc: Move functions inside struct

* Modernize bandwidth.cc: Review notes - remove extraneous checks, move small functions into .H file, etc

* Modernize bandwidth.cc: Construction and destruction is now via C++ new/delete

* Modernize bandwidth.cc: Rename used() to notifyBandwidthConsumed()

* Modernize bandwidth.cc: Children is now unordered_set

* Modernize bandwidth.cc: Allocation functions for peer bandwidth are now using std::vector instead of ptrArrays

* Modernize bandwidth.cc: Code formatting

* Modernize bandwidth.cc: Private fields after public; Minor review notes

* Modernize bandwidth.cc: Ungroup enums into constants; Docs minor update

* Modernize bitfield.cc: Docs comments changes; Using constexpr instead of const

Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
Dmytro Lytovchenko
2021-10-09 14:52:09 +02:00
committed by GitHub
parent 1ba64684f9
commit c287b82c00
11 changed files with 326 additions and 390 deletions

View File

@@ -64,6 +64,7 @@ public:
, base_url{ url }
, callback{ callback_in }
, callback_data{ callback_data_in }
, bandwidth(tor->bandwidth)
{
// init parent bits
tr_bitfieldSetHasAll(&have);
@@ -71,7 +72,6 @@ public:
file_urls.resize(tr_torrentInfo(tor)->fileCount);
tr_bandwidthConstruct(&bandwidth, &tor->bandwidth);
timer = evtimer_new(session->event_base, webseed_timer_func, this);
tr_timerAddMsec(timer, TR_IDLE_TIMER_MSEC);
}
@@ -83,7 +83,6 @@ public:
tasks.clear();
event_free(timer);
tr_bandwidthDestruct(&bandwidth);
}
bool is_transferring_pieces(uint64_t now, tr_direction direction, unsigned int* setme_Bps) const override
@@ -94,7 +93,7 @@ public:
if (direction == TR_DOWN)
{
is_active = !std::empty(tasks);
Bps = tr_bandwidthGetPieceSpeed_Bps(&bandwidth, now, direction);
Bps = bandwidth.getPieceSpeed_Bps(now, direction);
}
if (setme_Bps != nullptr)
@@ -110,7 +109,7 @@ public:
tr_peer_callback const callback;
void* const callback_data;
tr_bandwidth bandwidth = {};
tr_bandwidth bandwidth;
std::set<tr_webseed_task*> tasks;
struct event* timer = nullptr;
int consecutive_failures = 0;
@@ -288,7 +287,7 @@ static void on_content_changed(struct evbuffer* buf, struct evbuffer_cb_info con
uint32_t len;
struct tr_webseed* w = task->webseed;
tr_bandwidthUsed(&w->bandwidth, TR_DOWN, n_added, true, tr_time_msec());
w->bandwidth.notifyBandwidthConsumed(TR_DOWN, n_added, true, tr_time_msec());
fire_client_got_piece_data(w, n_added);
len = evbuffer_get_length(buf);