mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-13 20:56:17 +00:00
Cleaned up WindowHttpQueue.
This commit is contained in:
@@ -167,17 +167,12 @@ AC_DEFUN([TORRENT_CHECK_CACHELINE], [
|
|||||||
])],
|
])],
|
||||||
[
|
[
|
||||||
AC_MSG_RESULT(found builtin)
|
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.
|
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_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_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_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.)
|
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -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 "config.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
+2
-38
@@ -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
|
#ifndef RTORRENT_CORE_HTTP_QUEUE_H
|
||||||
#define RTORRENT_CORE_HTTP_QUEUE_H
|
#define RTORRENT_CORE_HTTP_QUEUE_H
|
||||||
|
|
||||||
@@ -47,10 +11,10 @@ class CurlGet;
|
|||||||
|
|
||||||
class HttpQueue : private std::list<CurlGet*> {
|
class HttpQueue : private std::list<CurlGet*> {
|
||||||
public:
|
public:
|
||||||
typedef std::list<CurlGet*> base_type;
|
typedef std::list<CurlGet*> base_type;
|
||||||
typedef std::function<CurlGet* ()> slot_factory;
|
typedef std::function<CurlGet* ()> slot_factory;
|
||||||
typedef std::function<void (CurlGet*)> slot_curl_get;
|
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::iterator;
|
||||||
using base_type::const_iterator;
|
using base_type::const_iterator;
|
||||||
|
|||||||
@@ -10,32 +10,43 @@
|
|||||||
|
|
||||||
namespace display {
|
namespace display {
|
||||||
|
|
||||||
|
// TODO: Large downloads result in rtorrent not quiting on ^Q.
|
||||||
|
|
||||||
WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) :
|
WindowHttpQueue::WindowHttpQueue(core::HttpQueue* q) :
|
||||||
Window(new Canvas, 0, 0, 1, extent_full, 1),
|
Window(new Canvas, 0, 0, 1, extent_full, 1),
|
||||||
m_queue(q) {
|
m_queue(q) {
|
||||||
|
|
||||||
set_active(false);
|
set_active(false);
|
||||||
m_connInsert = m_queue->signal_insert().insert(m_queue->signal_insert().end(),
|
m_conn_insert = m_queue->signal_insert().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_insert(h); });
|
||||||
std::bind(&WindowHttpQueue::receive_insert,
|
m_conn_erase = m_queue->signal_erase().insert(m_queue->signal_insert().end(), [this](auto* h) { receive_erase(h); });
|
||||||
this,
|
|
||||||
std::placeholders::_1));
|
m_task_deactivate.slot() = [this] {
|
||||||
m_connErase = m_queue->signal_erase().insert(m_queue->signal_insert().end(),
|
if (!m_container.empty())
|
||||||
std::bind(&WindowHttpQueue::receive_erase,
|
return;
|
||||||
this,
|
|
||||||
std::placeholders::_1));
|
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
|
void
|
||||||
WindowHttpQueue::redraw() {
|
WindowHttpQueue::redraw() {
|
||||||
|
bool is_empty = m_container.empty();
|
||||||
|
|
||||||
schedule_update();
|
schedule_update();
|
||||||
cleanup_list();
|
cleanup_list();
|
||||||
|
|
||||||
if (m_container.empty()) {
|
if (!is_empty && m_container.empty())
|
||||||
set_active(false);
|
torrent::this_thread::scheduler()->update_wait_for(&m_task_deactivate, 5s);
|
||||||
m_slot_adjust();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_canvas->erase();
|
m_canvas->erase();
|
||||||
m_canvas->print(0, 0, "Http [%i]", m_queue->size());
|
m_canvas->print(0, 0, "Http [%i]", m_queue->size());
|
||||||
@@ -43,15 +54,15 @@ WindowHttpQueue::redraw() {
|
|||||||
unsigned int pos = 10;
|
unsigned int pos = 10;
|
||||||
Container::iterator itr = m_container.begin();
|
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)
|
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)
|
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
|
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;
|
pos += itr->m_name.size() + 6;
|
||||||
++itr;
|
++itr;
|
||||||
@@ -60,14 +71,14 @@ WindowHttpQueue::redraw() {
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowHttpQueue::cleanup_list() {
|
WindowHttpQueue::cleanup_list() {
|
||||||
for (Container::iterator itr = m_container.begin(); itr != m_container.end();)
|
for (Container::iterator itr = m_container.begin(); itr != m_container.end(); ) {
|
||||||
if (itr->m_http == NULL && itr->m_timer < torrent::this_thread::cached_time())
|
if (itr->m_http == nullptr && itr->m_timer < torrent::this_thread::cached_time()) {
|
||||||
itr = m_container.erase(itr);
|
itr = m_container.erase(itr);
|
||||||
else
|
continue;
|
||||||
++itr;
|
}
|
||||||
|
|
||||||
// Bad, can't have this here as it is called from redraw().
|
++itr;
|
||||||
// mark_dirty();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
@@ -87,8 +98,8 @@ WindowHttpQueue::create_name(core::CurlGet* h) {
|
|||||||
n.substr(n.size() - 8) == ".TORRENT"))
|
n.substr(n.size() - 8) == ".TORRENT"))
|
||||||
n = n.substr(0, n.size() - 8);
|
n = n.substr(0, n.size() - 8);
|
||||||
|
|
||||||
if (n.size() > 30)
|
if (n.size() > 20)
|
||||||
n = n.substr(0, 30);
|
n = n.substr(0, 20);
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -107,13 +118,13 @@ WindowHttpQueue::receive_insert(core::CurlGet* h) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
WindowHttpQueue::receive_erase(core::CurlGet* h) {
|
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())
|
if (itr == m_container.end())
|
||||||
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
|
throw std::logic_error("WindowHttpQueue::receive_erase(...) tried to remove an object we don't have");
|
||||||
|
|
||||||
itr->m_http = NULL;
|
itr->m_http = nullptr;
|
||||||
itr->m_timer = torrent::this_thread::cached_time() + 1s;
|
itr->m_timer = torrent::this_thread::cached_time() + 4s;
|
||||||
|
|
||||||
mark_dirty();
|
mark_dirty();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,16 +19,15 @@ public:
|
|||||||
typedef std::list<slot_curl_get> signal_curl_get;
|
typedef std::list<slot_curl_get> signal_curl_get;
|
||||||
|
|
||||||
WindowHttpQueue(core::HttpQueue* q);
|
WindowHttpQueue(core::HttpQueue* q);
|
||||||
|
~WindowHttpQueue() override;
|
||||||
|
|
||||||
virtual void redraw();
|
void redraw() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Node {
|
struct Node {
|
||||||
Node(core::CurlGet* h, const std::string& n) : m_http(h), m_name(n) {}
|
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::string m_name;
|
||||||
std::chrono::microseconds m_timer{};
|
std::chrono::microseconds m_timer{};
|
||||||
};
|
};
|
||||||
@@ -45,8 +44,10 @@ private:
|
|||||||
core::HttpQueue* m_queue;
|
core::HttpQueue* m_queue;
|
||||||
Container m_container;
|
Container m_container;
|
||||||
|
|
||||||
signal_curl_get::iterator m_connInsert;
|
signal_curl_get::iterator m_conn_insert;
|
||||||
signal_curl_get::iterator m_connErase;
|
signal_curl_get::iterator m_conn_erase;
|
||||||
|
|
||||||
|
torrent::utils::SchedulerEntry m_task_deactivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user