Browse Source

Cleaned up WindowHttpQueue.

pull/1487/head
rakshasa 5 months ago
committed by Jari Sundell
parent
commit
9fe4d188e9
  1. 5
      scripts/common.m4
  2. 38
      src/core/http_queue.cc
  3. 40
      src/core/http_queue.h
  4. 69
      src/display/window_http_queue.cc
  5. 13
      src/display/window_http_queue.h

5
scripts/common.m4

@ -167,17 +167,12 @@ AC_DEFUN([TORRENT_CHECK_CACHELINE], [
])],
[
AC_MSG_RESULT(found builtin)
dnl AC_DEFINE(LT_SMP_CACHE_BYTES, SMP_CACHE_BYTES, Largest L1 cache size we know of, should work on all archs.)
dnl AC_DEFINE(lt_cacheline_aligned, __cacheline_aligned, LibTorrent defined cacheline aligned.)
dnl Need to fix this so that it uses the stuff defined by the system.
AC_DEFINE(LT_SMP_CACHE_BYTES, 128, Largest L1 cache size we know of should work on all archs.)
AC_DEFINE(lt_cacheline_aligned, __attribute__((__aligned__(LT_SMP_CACHE_BYTES))), LibTorrent defined cacheline aligned.)
], [
AC_MSG_RESULT(using default 128 bytes)
AC_DEFINE(LT_SMP_CACHE_BYTES, 128, Largest L1 cache size we know of should work on all archs.)
AC_DEFINE(lt_cacheline_aligned, __attribute__((__aligned__(LT_SMP_CACHE_BYTES))), LibTorrent defined cacheline aligned.)
])
])

38
src/core/http_queue.cc

@ -1,39 +1,3 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#include "config.h"
#include <memory>
@ -48,7 +12,7 @@ namespace core {
HttpQueue::iterator
HttpQueue::insert(const std::string& url, std::iostream* s) {
std::unique_ptr<CurlGet> h(m_slot_factory());
h->set_url(url);
h->set_stream(s);
h->set_timeout(5 * 60);

40
src/core/http_queue.h

@ -1,39 +1,3 @@
// rTorrent - BitTorrent client
// Copyright (C) 2005-2011, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
#ifndef RTORRENT_CORE_HTTP_QUEUE_H
#define RTORRENT_CORE_HTTP_QUEUE_H
@ -47,10 +11,10 @@ class CurlGet;
class HttpQueue : private std::list<CurlGet*> {
public:
typedef std::list<CurlGet*> base_type;
typedef std::list<CurlGet*> base_type;
typedef std::function<CurlGet* ()> slot_factory;
typedef std::function<void (CurlGet*)> slot_curl_get;
typedef std::list<slot_curl_get> signal_curl_get;
typedef std::list<slot_curl_get> signal_curl_get;
using base_type::iterator;
using base_type::const_iterator;

69
src/display/window_http_queue.cc

@ -10,32 +10,43 @@
namespace display {
// TODO: Large downloads result in rtorrent not quiting on ^Q.
WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) :
Window(new Canvas, 0, 0, 1, extent_full, 1),
m_queue(q) {
set_active(false);
m_connInsert = m_queue->signal_insert().insert(m_queue->signal_insert().end(),
std::bind(&WindowHttpQueue::receive_insert,
this,
std::placeholders::_1));
m_connErase = m_queue->signal_erase().insert(m_queue->signal_insert().end(),
std::bind(&WindowHttpQueue::receive_erase,
this,
std::placeholders::_1));
m_conn_insert = m_queue->signal_insert().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_insert(h); });
m_conn_erase = m_queue->signal_erase().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_erase(h); });
m_task_deactivate.slot() = [this] {
if (!m_container.empty())
return;
set_active(false);
m_slot_adjust();
mark_dirty();
};
}
WindowHttpQueue::~WindowHttpQueue() {
m_queue->signal_insert().erase(m_conn_insert);
m_queue->signal_erase().erase(m_conn_erase);
torrent::this_thread::scheduler()->erase(&m_task_deactivate);
}
void
WindowHttpQueue::redraw() {
bool is_empty = m_container.empty();
schedule_update();
cleanup_list();
if (m_container.empty()) {
set_active(false);
m_slot_adjust();
return;
}
if (!is_empty && m_container.empty())
torrent::this_thread::scheduler()->update_wait_for(&m_task_deactivate, 5s);
m_canvas->erase();
m_canvas->print(0, 0, "Http [%i]", m_queue->size());
@ -43,15 +54,15 @@ WindowHttpQueue::redraw() {
unsigned int pos = 10;
Container::iterator itr = m_container.begin();
while (itr != m_container.end() && pos + 20 < m_canvas->width()) {
while (itr != m_container.end() && pos + 10 < m_canvas->width()) {
if (itr->m_http == NULL)
m_canvas->print(pos, 0, "%s done", itr->m_name.c_str());
m_canvas->print(pos, 0, "[%s done]", itr->m_name.c_str());
else if (itr->m_http->size_total() == 0)
m_canvas->print(pos, 0, "%s ---%%", itr->m_name.c_str());
m_canvas->print(pos, 0, "[%s ---%%]", itr->m_name.c_str());
else
m_canvas->print(pos, 0, "%s %3i%%", itr->m_name.c_str(), (int)(100.0 * itr->m_http->size_done() / itr->m_http->size_total()));
m_canvas->print(pos, 0, "[%s %3i%%]", itr->m_name.c_str(), (int)(100.0 * itr->m_http->size_done() / itr->m_http->size_total()));
pos += itr->m_name.size() + 6;
++itr;
@ -60,14 +71,14 @@ WindowHttpQueue::redraw() {
void
WindowHttpQueue::cleanup_list() {
for (Container::iterator itr = m_container.begin(); itr != m_container.end();)
if (itr->m_http == NULL && itr->m_timer < torrent::this_thread::cached_time())
for (Container::iterator itr = m_container.begin(); itr != m_container.end(); ) {
if (itr->m_http == nullptr && itr->m_timer < torrent::this_thread::cached_time()) {
itr = m_container.erase(itr);
else
++itr;
continue;
}
// Bad, can't have this here as it is called from redraw().
// mark_dirty();
++itr;
}
}
std::string
@ -87,8 +98,8 @@ WindowHttpQueue::create_name(core::CurlGet* h) {
n.substr(n.size() - 8) == ".TORRENT"))
n = n.substr(0, n.size() - 8);
if (n.size() > 30)
n = n.substr(0, 30);
if (n.size() > 20)
n = n.substr(0, 20);
return n;
}
@ -107,13 +118,13 @@ WindowHttpQueue::receive_insert(core::CurlGet* h) {
void
WindowHttpQueue::receive_erase(core::CurlGet* h) {
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), [h](Node n) { return h == n.get_http(); });
Container::iterator itr = std::find_if(m_container.begin(), m_container.end(), [h](Node& n) { return h == n.m_http; });
if (itr == m_container.end())
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
itr->m_http = NULL;
itr->m_timer = torrent::this_thread::cached_time() + 1s;
itr->m_http = nullptr;
itr->m_timer = torrent::this_thread::cached_time() + 4s;
mark_dirty();
}

13
src/display/window_http_queue.h

@ -19,16 +19,15 @@ public:
typedef std::list<slot_curl_get> signal_curl_get;
WindowHttpQueue(core::HttpQueue* q);
~WindowHttpQueue() override;
virtual void redraw();
void redraw() override;
private:
struct Node {
Node(core::CurlGet* h, const std::string& n) : m_http(h), m_name(n) {}
core::CurlGet* get_http() { return m_http; }
core::CurlGet* m_http;
core::CurlGet* m_http{};
std::string m_name;
std::chrono::microseconds m_timer{};
};
@ -45,8 +44,10 @@ private:
core::HttpQueue* m_queue;
Container m_container;
signal_curl_get::iterator m_connInsert;
signal_curl_get::iterator m_connErase;
signal_curl_get::iterator m_conn_insert;
signal_curl_get::iterator m_conn_erase;
torrent::utils::SchedulerEntry m_task_deactivate;
};
}

Loading…
Cancel
Save