From 6a444ab4de8010055536c0a21d0e0bdf307af958 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Wed, 7 Dec 2011 16:09:13 +0900 Subject: [PATCH 01/11] Added unittest script to gitignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index c97ffecf..da570fdf 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ scripts/ltoptions.m4 scripts/ltsugar.m4 scripts/ltversion.m4 scripts/lt~obsolete.m4 + +test/rtorrentTest From 4353f1bfa8686a177088822fdebc9909782154f6 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Fri, 9 Dec 2011 03:01:53 +0900 Subject: [PATCH 02/11] Highlight busy trackers in an easier to see way. --- src/display/window_tracker_list.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/display/window_tracker_list.cc b/src/display/window_tracker_list.cc index ac2d78dc..3dcee109 100644 --- a/src/display/window_tracker_list.cc +++ b/src/display/window_tracker_list.cc @@ -83,11 +83,6 @@ WindowTrackerList::redraw() { while (range.first != range.second) { torrent::Tracker* tracker = tl->at(range.first); -// m_canvas->print(0, pos, "[%c] [S/L %5i/%5i] %s", -// tracker->is_enabled() ? (tracker->is_open() ? '*' : ' ') : '-', -// tracker->scrape_complete(), tracker->scrape_incomplete(), -// tracker->url().c_str()); - if (tracker->group() == group) m_canvas->print(0, pos, "%2i:", group++); @@ -95,30 +90,27 @@ WindowTrackerList::redraw() { tracker->url().c_str()); if (pos < m_canvas->height()) - m_canvas->print(4, pos++, "Id: %s Counters: %uf / %us (%u) %s %s S/L/D: %u/%u/%u (%u/%u)", + m_canvas->print(0, pos++, "%s Id: %s Counters: %uf / %us (%u) %s S/L/D: %u/%u/%u (%u/%u)", + tracker->is_busy() ? "req " : " ", rak::copy_escape_html(tracker->tracker_id()).c_str(), tracker->failed_counter(), tracker->success_counter(), tracker->scrape_counter(), tracker->is_usable() ? " on" : tracker->is_enabled() ? "err" : "off", - tracker->is_busy() ? "req" : " ", tracker->scrape_complete(), tracker->scrape_incomplete(), tracker->scrape_downloaded(), tracker->latest_new_peers(), tracker->latest_sum_peers()); -// m_canvas->print(4, pos++, "Id: %s Focus: %s Enabled: %s Open: %s Timer: %u/%u", -// rak::copy_escape_html(tracker->tracker_id()).c_str(), -// range.first == tl->focus() ? "yes" : " no", -// tracker->is_enabled() ? "yes" : " no", -// tracker->is_open() ? "yes" : " no", -// tracker->normal_interval(), -// tracker->min_interval()); - if (range.first == *m_focus) { - m_canvas->set_attr(0, pos - 2, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0)); - m_canvas->set_attr(0, pos - 1, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0)); + m_canvas->set_attr(4, pos - 2, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0)); + m_canvas->set_attr(4, pos - 1, m_canvas->width(), is_focused() ? A_REVERSE : A_BOLD, COLOR_PAIR(0)); + } + + if (tracker->is_busy()) { + m_canvas->set_attr(0, pos - 2, 4, A_REVERSE, COLOR_PAIR(0)); + m_canvas->set_attr(0, pos - 1, 4, A_REVERSE, COLOR_PAIR(0)); } range.first++; From 1bbb7aa793b58d02b2a47e080e747e08236b8afb Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Fri, 9 Dec 2011 20:05:49 +0900 Subject: [PATCH 03/11] Bumped version. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index f8d4cbe9..fa1329a3 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(rtorrent, 0.8.9, jaris@ifi.uio.no) +AC_INIT(rtorrent, 0.9.0, jaris@ifi.uio.no) AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) @@ -39,7 +39,7 @@ PKG_CHECK_MODULES(libcurl, libcurl >= 7.15.4, CXXFLAGS="$CXXFLAGS $libcurl_CFLAGS"; LIBS="$LIBS $libcurl_LIBS") -PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.12.9, +PKG_CHECK_MODULES(libtorrent, libtorrent >= 0.13.0, CXXFLAGS="$CXXFLAGS $libtorrent_CFLAGS"; LIBS="$LIBS $libtorrent_LIBS") From 081b5e9cb26dbce1d2371cac3a577c19cefbedcd Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sat, 10 Dec 2011 22:58:02 +0900 Subject: [PATCH 04/11] Removed old file entry. --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 8d021287..f3c8a930 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,6 @@ EXTRA_DIST= \ rak/partial_queue.h \ rak/priority_queue.h \ rak/priority_queue_default.h \ - rak/ranges.h \ rak/regex.h \ rak/socket_address.h \ rak/string_manip.h \ From 21944b941a7a418f7bdc56ff5a5bc5965c2b65c9 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sun, 11 Dec 2011 12:21:24 +0900 Subject: [PATCH 05/11] Make sure we don't access freed memory if a download is erased during the erased event. --- src/core/download_list.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/download_list.cc b/src/core/download_list.cc index 939e6ff7..e255434f 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -642,6 +642,9 @@ DownloadList::confirm_finished(Download* download) { DL_TRIGGER_EVENT(download, "event.download.finished"); + if (find(infohash) != end()) + return; + // if (download->resume_flags() != ~uint32_t()) // throw torrent::internal_error("DownloadList::confirm_finished(...) download->resume_flags() != ~uint32_t()."); @@ -655,8 +658,7 @@ DownloadList::confirm_finished(Download* download) { // being hashed. download->set_resume_flags(~uint32_t()); - if (find(infohash) != end() && - !download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1) + if (!download->is_active() && rpc::call_command_value("d.state", rpc::make_target(download)) == 1) resume(download, torrent::Download::start_no_create | torrent::Download::start_skip_tracker | From a2ad162fe39d85662b542ddc75ab5a9e959b0481 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sun, 11 Dec 2011 15:41:05 +0900 Subject: [PATCH 06/11] Don't display scrape requests. --- src/display/utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display/utils.cc b/src/display/utils.cc index b67ce632..2ab4c1a7 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -195,10 +195,10 @@ print_download_status(char* first, char* last, core::Download* d) { first = print_buffer(first, last, "Checking hash [%2i%%]", (d->download()->chunks_hashed() * 100) / d->download()->file_list()->size_chunks()); - } else if (d->tracker_list()->has_active()) { + } else if (d->tracker_list()->has_active_not_scrape()) { torrent::TrackerList::iterator itr = std::find_if(d->tracker_list()->begin(), d->tracker_list()->end(), - std::mem_fun(&torrent::Tracker::is_busy)); + std::mem_fun(&torrent::Tracker::is_busy_not_scrape)); char status[128]; (*itr)->get_status(status, sizeof(status)); From 2d8036e3a83d1a9cc48b253424ee8e1831b8b511 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sun, 11 Dec 2011 17:52:10 +0900 Subject: [PATCH 07/11] Use new API call. --- src/core/manager.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/manager.cc b/src/core/manager.cc index d36e78fa..b2d431ae 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -206,7 +206,7 @@ Manager::get_address_throttle(const sockaddr* addr) { // Most of this should be possible to move out. void Manager::initialize_second() { - torrent::Http::set_factory(std::bind(&CurlStack::new_object, m_httpStack)); + torrent::Http::slot_factory() = std::bind(&CurlStack::new_object, m_httpStack); m_httpQueue->slot_factory(sigc::mem_fun(m_httpStack, &CurlStack::new_object)); CurlStack::global_init(); From 89213982d5b38b2d8ad9d7b2ccc38a515df8ac6f Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 12 Dec 2011 00:03:50 +0900 Subject: [PATCH 08/11] Moving thread code to libtorrent. --- src/thread_base.cc | 25 +++++++------------------ src/thread_base.h | 19 +++---------------- src/thread_main.cc | 1 + src/thread_worker.cc | 1 + 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/thread_base.cc b/src/thread_base.cc index 936f382c..4996e223 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -108,13 +108,7 @@ public: void throw_shutdown_exception() { throw torrent::shutdown_exception(); } ThreadBase::ThreadBase() : - m_state(STATE_UNKNOWN), m_pollManager(NULL) { - // Init the poll manager in a special init function called by the - // thread itself. Need to be careful with what external stuff - // create_poll_manager calls in that case. - std::memset(&m_thread, 0, sizeof(pthread_t)); - m_taskShutdown.set_slot(rak::ptr_fn(&throw_shutdown_exception)); m_threadQueue = new thread_queue_hack; @@ -149,24 +143,19 @@ ThreadBase::client_next_timeout() { } void* -ThreadBase::event_loop(ThreadBase* threadBase) { - // Setup stuff... - threadBase->m_state = STATE_ACTIVE; - - // Set local poll and priority queue. +ThreadBase::event_loop(ThreadBase* thread) { + thread->m_state = STATE_ACTIVE; try { while (true) { // Check for new queued items set by other threads. - if (!threadBase->m_threadQueue->empty()) - threadBase->call_queued_items(); + if (!thread->m_threadQueue->empty()) + thread->call_queued_items(); - // // Remember to add global lock thing to the main poll loop ++. + rak::priority_queue_perform(&thread->m_taskScheduler, cachedTime); - rak::priority_queue_perform(&threadBase->m_taskScheduler, cachedTime); - - threadBase->m_pollManager->poll_simple(threadBase->client_next_timeout()); + thread->m_pollManager->poll_simple(thread->client_next_timeout()); } } catch (torrent::shutdown_exception& e) { @@ -175,7 +164,7 @@ ThreadBase::event_loop(ThreadBase* threadBase) { release_global_lock(); } - threadBase->m_state = STATE_INACTIVE; + thread->m_state = STATE_INACTIVE; __sync_synchronize(); return NULL; diff --git a/src/thread_base.h b/src/thread_base.h index 8b4013c2..0698d9d8 100644 --- a/src/thread_base.h +++ b/src/thread_base.h @@ -39,7 +39,7 @@ #include #include -#include +#include #include "rak/priority_queue_default.h" #include "core/poll_manager.h" @@ -50,25 +50,15 @@ struct thread_queue_hack; struct thread_queue_hack; -class ThreadBase : public torrent::ThreadBase { +class ThreadBase : public torrent::thread_base { public: typedef rak::priority_queue_default priority_queue; typedef void (*thread_base_func)(ThreadBase*); typedef void* (*pthread_func)(void*); - enum state_type { - STATE_UNKNOWN, - STATE_INITIALIZED, - STATE_ACTIVE, - STATE_INACTIVE - }; - ThreadBase(); virtual ~ThreadBase(); - bool is_active() const { return m_state == STATE_ACTIVE; } - - torrent::Poll* poll() { return m_pollManager->get_torrent_poll(); } core::PollManager* poll_manager() { return m_pollManager; } priority_queue& task_scheduler() { return m_taskScheduler; } @@ -82,7 +72,7 @@ public: void queue_item(thread_base_func newFunc); - static void* event_loop(ThreadBase* threadBase); + static void* event_loop(ThreadBase* thread); // Only call this when global lock has been acquired, as it checks // ThreadBase::is_main_polling() which is only guaranteed to remain @@ -99,9 +89,6 @@ protected: // TODO: Add thread name. - pthread_t m_thread; - state_type m_state; - // The timer needs to be sync'ed when updated... core::PollManager* m_pollManager; diff --git a/src/thread_main.cc b/src/thread_main.cc index b87cae52..d41997b7 100644 --- a/src/thread_main.cc +++ b/src/thread_main.cc @@ -51,6 +51,7 @@ ThreadMain::init_thread() { m_pollManager = core::PollManager::create_poll_manager(); m_pollManager->get_torrent_poll()->set_flags(torrent::Poll::flag_waive_global_lock); + m_poll = m_pollManager->get_torrent_poll(); m_state = STATE_INITIALIZED; m_thread = pthread_self(); diff --git a/src/thread_worker.cc b/src/thread_worker.cc index cdfe3323..e955e10e 100644 --- a/src/thread_worker.cc +++ b/src/thread_worker.cc @@ -63,6 +63,7 @@ ThreadWorker::~ThreadWorker() { void ThreadWorker::init_thread() { m_pollManager = core::PollManager::create_poll_manager(); + m_poll = m_pollManager->get_torrent_poll(); m_state = STATE_INITIALIZED; } From 6dfd2fe0cddd5683df8caea04ed4504930ab9dac Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 12 Dec 2011 01:46:09 +0900 Subject: [PATCH 09/11] Moved polling code to libtorrent. --- src/core/poll_manager_epoll.cc | 28 ++------------------ src/core/poll_manager_kqueue.cc | 28 ++------------------ src/core/poll_manager_select.cc | 47 ++------------------------------- src/core/poll_manager_select.h | 3 --- 4 files changed, 6 insertions(+), 100 deletions(-) diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc index 8b7670db..f4b7b1f8 100644 --- a/src/core/poll_manager_epoll.cc +++ b/src/core/poll_manager_epoll.cc @@ -63,36 +63,12 @@ PollManagerEPoll::~PollManagerEPoll() { void PollManagerEPoll::poll(rak::timer timeout) { - // Add 1ms to ensure we don't idle loop due to the lack of - // resolution. - torrent::perform(); - timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; - - ThreadBase::release_global_lock(); - ThreadBase::entering_main_polling(); - - int status = static_cast(m_poll)->poll((timeout.usec() + 999) / 1000); - - ThreadBase::leaving_main_polling(); - ThreadBase::acquire_global_lock(); - - if (status == -1) - return check_error(); - - torrent::perform(); - static_cast(m_poll)->perform(); + static_cast(m_poll)->do_poll(); } void PollManagerEPoll::poll_simple(rak::timer timeout) { - // Add 1ms to ensure we don't idle loop due to the lack of - // resolution. - timeout = timeout + 1000; - - if (static_cast(m_poll)->poll((timeout.usec() + 999) / 1000) == -1) - return check_error(); - - static_cast(m_poll)->perform(); + static_cast(m_poll)->do_poll(torrent::Poll::poll_worker_thread); } } diff --git a/src/core/poll_manager_kqueue.cc b/src/core/poll_manager_kqueue.cc index 5bf309e7..572f35e4 100644 --- a/src/core/poll_manager_kqueue.cc +++ b/src/core/poll_manager_kqueue.cc @@ -64,36 +64,12 @@ PollManagerKQueue::~PollManagerKQueue() { void PollManagerKQueue::poll(rak::timer timeout) { - // Add 1ms to ensure we don't idle loop due to the lack of - // resolution. - torrent::perform(); - timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; - - ThreadBase::release_global_lock(); - ThreadBase::entering_main_polling(); - - int status = static_cast(m_poll)->poll((timeout.usec() + 999) / 1000); - - ThreadBase::leaving_main_polling(); - ThreadBase::acquire_global_lock(); - - if (status == -1) - return check_error(); - - torrent::perform(); - static_cast(m_poll)->perform(); + static_cast(m_poll)->do_poll(); } void PollManagerKQueue::poll_simple(rak::timer timeout) { - // Add 1ms to ensure we don't idle loop due to the lack of - // resolution. - timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; - - if (static_cast(m_poll)->poll((timeout.usec() + 999) / 1000) == -1) - return check_error(); - - static_cast(m_poll)->perform(); + static_cast(m_poll)->do_poll(torrent::Poll::poll_worker_thread); } } diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc index 70d9fd1d..6d4827b9 100644 --- a/src/core/poll_manager_select.cc +++ b/src/core/poll_manager_select.cc @@ -53,13 +53,6 @@ namespace core { PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) { #if defined USE_VARIABLE_FDSET m_setSize = (m_poll->open_max() + 7) / 8; - - char* buffer = rak::cacheline_allocator::alloc_size(3 * m_setSize); - std::memset(buffer, 0, 3 * m_setSize); - - m_readSet = (fd_set*)buffer; - m_writeSet = (fd_set*)(buffer += m_setSize); - m_errorSet = (fd_set*)(buffer += m_setSize); #else #error Only variable fdset supported atm. #endif @@ -76,52 +69,16 @@ PollManagerSelect::create(int maxOpenSockets) { } PollManagerSelect::~PollManagerSelect() { - free(m_readSet); } void PollManagerSelect::poll(rak::timer timeout) { - torrent::perform(); - timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; - - std::memset(m_readSet, 0, m_setSize); - std::memset(m_writeSet, 0, m_setSize); - std::memset(m_errorSet, 0, m_setSize); - - unsigned int maxFd = static_cast(m_poll)->fdset(m_readSet, m_writeSet, m_errorSet); - - timeval t = timeout.tval(); - - ThreadBase::entering_main_polling(); - ThreadBase::release_global_lock(); - - int status = select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t); - - ThreadBase::leaving_main_polling(); - ThreadBase::acquire_global_lock(); - - if (status == -1) - return check_error(); - - torrent::perform(); - static_cast(m_poll)->perform(m_readSet, m_writeSet, m_errorSet); + static_cast(m_poll)->do_poll(); } void PollManagerSelect::poll_simple(rak::timer timeout) { - torrent::PollSelect* currentPoll = static_cast(m_poll); - - timeout = timeout + 1000; - std::memset(m_readSet, 0, 3 * m_setSize); - - unsigned int maxFd = currentPoll->fdset(m_readSet, m_writeSet, m_errorSet); - - timeval t = timeout.tval(); - - if (select(maxFd + 1, m_readSet, m_writeSet, m_errorSet, &t) == -1) - return check_error(); - - currentPoll->perform(m_readSet, m_writeSet, m_errorSet); + static_cast(m_poll)->do_poll(torrent::PollSelect::poll_worker_thread); } } diff --git a/src/core/poll_manager_select.h b/src/core/poll_manager_select.h index 8aa46e43..18082360 100644 --- a/src/core/poll_manager_select.h +++ b/src/core/poll_manager_select.h @@ -57,9 +57,6 @@ private: PollManagerSelect(torrent::Poll* p); unsigned int m_setSize; - fd_set* m_readSet; - fd_set* m_writeSet; - fd_set* m_errorSet; }; } From 4d1f5dce67f15094dba1b73dc75aeaf7620a3ecd Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 12 Dec 2011 02:58:16 +0900 Subject: [PATCH 10/11] Fixed poll arguments. --- src/core/poll_manager_epoll.cc | 4 ++-- src/core/poll_manager_kqueue.cc | 4 ++-- src/core/poll_manager_select.cc | 6 ++++-- src/main.cc | 2 +- src/thread_base.h | 1 - 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc index f4b7b1f8..123efbf9 100644 --- a/src/core/poll_manager_epoll.cc +++ b/src/core/poll_manager_epoll.cc @@ -63,12 +63,12 @@ PollManagerEPoll::~PollManagerEPoll() { void PollManagerEPoll::poll(rak::timer timeout) { - static_cast(m_poll)->do_poll(); + static_cast(m_poll)->do_poll(timeout.usec()); } void PollManagerEPoll::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(torrent::Poll::poll_worker_thread); + static_cast(m_poll)->do_poll(timeout.usec(), torrent::Poll::poll_worker_thread); } } diff --git a/src/core/poll_manager_kqueue.cc b/src/core/poll_manager_kqueue.cc index 572f35e4..82057ed5 100644 --- a/src/core/poll_manager_kqueue.cc +++ b/src/core/poll_manager_kqueue.cc @@ -64,12 +64,12 @@ PollManagerKQueue::~PollManagerKQueue() { void PollManagerKQueue::poll(rak::timer timeout) { - static_cast(m_poll)->do_poll(); + static_cast(m_poll)->do_poll(timeout.usec()); } void PollManagerKQueue::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(torrent::Poll::poll_worker_thread); + static_cast(m_poll)->do_poll(timeout.usec(), torrent::Poll::poll_worker_thread); } } diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc index 6d4827b9..bcd2d390 100644 --- a/src/core/poll_manager_select.cc +++ b/src/core/poll_manager_select.cc @@ -73,12 +73,14 @@ PollManagerSelect::~PollManagerSelect() { void PollManagerSelect::poll(rak::timer timeout) { - static_cast(m_poll)->do_poll(); + // timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; + + static_cast(m_poll)->do_poll(timeout.usec()); } void PollManagerSelect::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(torrent::PollSelect::poll_worker_thread); + static_cast(m_poll)->do_poll(timeout.usec(), torrent::PollSelect::poll_worker_thread); } } diff --git a/src/main.cc b/src/main.cc index 43474d6e..5dfdc987 100644 --- a/src/main.cc +++ b/src/main.cc @@ -878,7 +878,7 @@ main(int argc, char** argv) { rak::priority_queue_perform(&taskScheduler, cachedTime); // Do shutdown check before poll, not after. - main_thread->poll_manager()->poll(client_next_timeout(control)); + main_thread->poll()->do_poll(client_next_timeout(control).usec()); } control->core()->download_list()->session_save(); diff --git a/src/thread_base.h b/src/thread_base.h index 0698d9d8..5ac89ee2 100644 --- a/src/thread_base.h +++ b/src/thread_base.h @@ -59,7 +59,6 @@ public: ThreadBase(); virtual ~ThreadBase(); - core::PollManager* poll_manager() { return m_pollManager; } priority_queue& task_scheduler() { return m_taskScheduler; } virtual void init_thread() = 0; From ee859a61375ad3919ebab41b730b6edcdaaeb21a Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 12 Dec 2011 03:32:36 +0900 Subject: [PATCH 11/11] Removed deprecated PollManager files. --- src/core/Makefile.am | 6 --- src/core/manager.cc | 4 +- src/core/poll_manager.cc | 64 +++++++++--------------- src/core/poll_manager.h | 28 +---------- src/core/poll_manager_epoll.cc | 74 ---------------------------- src/core/poll_manager_epoll.h | 64 ------------------------ src/core/poll_manager_kqueue.cc | 75 ---------------------------- src/core/poll_manager_kqueue.h | 64 ------------------------ src/core/poll_manager_select.cc | 86 --------------------------------- src/core/poll_manager_select.h | 64 ------------------------ src/thread_base.cc | 6 +-- src/thread_base.h | 1 - src/thread_main.cc | 5 +- src/thread_worker.cc | 4 +- 14 files changed, 31 insertions(+), 514 deletions(-) delete mode 100644 src/core/poll_manager_epoll.cc delete mode 100644 src/core/poll_manager_epoll.h delete mode 100644 src/core/poll_manager_kqueue.cc delete mode 100644 src/core/poll_manager_kqueue.h delete mode 100644 src/core/poll_manager_select.cc delete mode 100644 src/core/poll_manager_select.h diff --git a/src/core/Makefile.am b/src/core/Makefile.am index fe07cbfe..57a2a49f 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -26,12 +26,6 @@ libsub_core_a_SOURCES = \ manager.h \ poll_manager.cc \ poll_manager.h \ - poll_manager_epoll.cc \ - poll_manager_epoll.h \ - poll_manager_kqueue.cc \ - poll_manager_kqueue.h \ - poll_manager_select.cc \ - poll_manager_select.h \ range_map.h \ view.cc \ view.h \ diff --git a/src/core/manager.cc b/src/core/manager.cc index b2d431ae..0539e413 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -71,9 +71,7 @@ #include "download_store.h" #include "http_queue.h" #include "manager.h" -#include "poll_manager_epoll.h" -#include "poll_manager_kqueue.h" -#include "poll_manager_select.h" +#include "poll_manager.h" #include "view.h" namespace std { using namespace tr1; } diff --git a/src/core/poll_manager.cc b/src/core/poll_manager.cc index 85d7de79..e9f64afc 100644 --- a/src/core/poll_manager.cc +++ b/src/core/poll_manager.cc @@ -39,71 +39,55 @@ #include #include #include +#include +#include +#include #include "globals.h" #include "control.h" #include "manager.h" #include "poll_manager.h" -#include "poll_manager_epoll.h" -#include "poll_manager_kqueue.h" -#include "poll_manager_select.h" namespace core { -PollManager::PollManager(torrent::Poll* poll) : - m_poll(poll) { - - if (m_poll == NULL) - throw std::logic_error("PollManager::PollManager(...) received poll == NULL"); -} - -PollManager::~PollManager() { - delete m_poll; -} - -PollManager* -PollManager::create_poll_manager() { - PollManager* pollManager = NULL; +torrent::Poll* +create_poll() { Log* log = &control->core()->get_log_important(); - const char* poll = getenv("RTORRENT_POLL"); + const char* poll_name = getenv("RTORRENT_POLL"); int maxOpen = sysconf(_SC_OPEN_MAX); - if (poll != NULL) { - if (!strcmp(poll, "epoll")) - pollManager = PollManagerEPoll::create(maxOpen); - else if (!strcmp(poll, "kqueue")) - pollManager = PollManagerKQueue::create(maxOpen); - else if (!strcmp(poll, "select")) - pollManager = PollManagerSelect::create(maxOpen); + torrent::Poll* poll = NULL; - if (pollManager == NULL) - log->push_front(std::string("Cannot enable '") + poll + "' based polling."); + if (poll_name != NULL) { + if (!strcmp(poll_name, "epoll")) + poll = torrent::PollEPoll::create(maxOpen); + else if (!strcmp(poll_name, "kqueue")) + poll = torrent::PollKQueue::create(maxOpen); + else if (!strcmp(poll_name, "select")) + poll = torrent::PollSelect::create(maxOpen); + + if (poll == NULL) + log->push_front(std::string("Cannot enable '") + poll_name + "' based polling."); } - if (pollManager != NULL) - log->push_front(std::string("Using '") + poll + "' based polling."); + if (poll != NULL) + log->push_front(std::string("Using '") + poll_name + "' based polling."); - else if ((pollManager = PollManagerEPoll::create(maxOpen)) != NULL) + else if ((poll = torrent::PollEPoll::create(maxOpen)) != NULL) log->push_front("Using 'epoll' based polling."); - else if ((pollManager = PollManagerKQueue::create(maxOpen)) != NULL) + else if ((poll = torrent::PollKQueue::create(maxOpen)) != NULL) log->push_front("Using 'kqueue' based polling."); - else if ((pollManager = PollManagerSelect::create(maxOpen)) != NULL) + else if ((poll = torrent::PollSelect::create(maxOpen)) != NULL) log->push_front("Using 'select' based polling."); else - throw std::runtime_error("Could not create any PollManager."); + throw std::runtime_error("Could not create any Poll object."); - return pollManager; -} - -void -PollManager::check_error() { - if (rak::error_number::current().value() != rak::error_number::e_intr) - throw std::runtime_error("Poll::work(): " + std::string(rak::error_number::current().c_str())); + return poll; } } diff --git a/src/core/poll_manager.h b/src/core/poll_manager.h index 5b9e6507..cfd40fc6 100644 --- a/src/core/poll_manager.h +++ b/src/core/poll_manager.h @@ -45,33 +45,7 @@ namespace core { -// CurlStack really should be somewhere else, but that won't happen -// until they add an epoll friendly API. - -class PollManager { -public: - typedef sigc::signal0 Signal; - - PollManager(torrent::Poll* poll); - virtual ~PollManager(); - - unsigned int get_open_max() const { return m_poll->open_max(); } - - torrent::Poll* get_torrent_poll() { return m_poll; } - - virtual void poll(rak::timer timeout) = 0; - virtual void poll_simple(rak::timer timeout) = 0; - - static PollManager* create_poll_manager(); - -protected: - PollManager(const PollManager&); - void operator = (const PollManager&); - - void check_error(); - - torrent::Poll* m_poll; -}; +torrent::Poll* create_poll(); } diff --git a/src/core/poll_manager_epoll.cc b/src/core/poll_manager_epoll.cc deleted file mode 100644 index 123efbf9..00000000 --- a/src/core/poll_manager_epoll.cc +++ /dev/null @@ -1,74 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "poll_manager_epoll.h" -#include "thread_base.h" - -namespace core { - -PollManagerEPoll* -PollManagerEPoll::create(int maxOpenSockets) { - torrent::PollEPoll* p = torrent::PollEPoll::create(maxOpenSockets); - - if (p == NULL) - return NULL; - else - return new PollManagerEPoll(p); -} - -PollManagerEPoll::~PollManagerEPoll() { -} - -void -PollManagerEPoll::poll(rak::timer timeout) { - static_cast(m_poll)->do_poll(timeout.usec()); -} - -void -PollManagerEPoll::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(timeout.usec(), torrent::Poll::poll_worker_thread); -} - -} diff --git a/src/core/poll_manager_epoll.h b/src/core/poll_manager_epoll.h deleted file mode 100644 index b000c640..00000000 --- a/src/core/poll_manager_epoll.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_CORE_POLL_MANAGER_EPOLL_H -#define RTORRENT_CORE_POLL_MANAGER_EPOLL_H - -#include "poll_manager.h" - -namespace torrent { - class PollEPoll; -} - -namespace core { - -class PollManagerEPoll : public PollManager { -public: - static PollManagerEPoll* create(int maxOpenSockets); - ~PollManagerEPoll(); - - torrent::Poll* get_torrent_poll(); - - void poll(rak::timer timeout); - void poll_simple(rak::timer timeout); - -private: - PollManagerEPoll(torrent::Poll* p) : PollManager(p) {} -}; - -} - -#endif diff --git a/src/core/poll_manager_kqueue.cc b/src/core/poll_manager_kqueue.cc deleted file mode 100644 index 82057ed5..00000000 --- a/src/core/poll_manager_kqueue.cc +++ /dev/null @@ -1,75 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "poll_manager_kqueue.h" -#include "thread_base.h" - -namespace core { - -PollManagerKQueue* -PollManagerKQueue::create(int maxOpenSockets) { - torrent::PollKQueue* p = torrent::PollKQueue::create(maxOpenSockets); - - if (p == NULL) - return NULL; - else - return new PollManagerKQueue(p); -} - -PollManagerKQueue::~PollManagerKQueue() { -} - -void -PollManagerKQueue::poll(rak::timer timeout) { - static_cast(m_poll)->do_poll(timeout.usec()); -} - -void -PollManagerKQueue::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(timeout.usec(), torrent::Poll::poll_worker_thread); -} - -} diff --git a/src/core/poll_manager_kqueue.h b/src/core/poll_manager_kqueue.h deleted file mode 100644 index 1c3bd0b9..00000000 --- a/src/core/poll_manager_kqueue.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_CORE_POLL_MANAGER_KQUEUE_H -#define RTORRENT_CORE_POLL_MANAGER_KQUEUE_H - -#include "poll_manager.h" - -namespace torrent { - class PollKQueue; -} - -namespace core { - -class PollManagerKQueue : public PollManager { -public: - static PollManagerKQueue* create(int maxOpenSockets); - ~PollManagerKQueue(); - - torrent::Poll* get_torrent_poll(); - - void poll(rak::timer timeout); - void poll_simple(rak::timer timeout); - -private: - PollManagerKQueue(torrent::Poll* p) : PollManager(p) {} -}; - -} - -#endif diff --git a/src/core/poll_manager_select.cc b/src/core/poll_manager_select.cc deleted file mode 100644 index bcd2d390..00000000 --- a/src/core/poll_manager_select.cc +++ /dev/null @@ -1,86 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "poll_manager_select.h" -#include "thread_base.h" - -namespace core { - -PollManagerSelect::PollManagerSelect(torrent::Poll* p) : PollManager(p) { -#if defined USE_VARIABLE_FDSET - m_setSize = (m_poll->open_max() + 7) / 8; -#else -#error Only variable fdset supported atm. -#endif -} - -PollManagerSelect* -PollManagerSelect::create(int maxOpenSockets) { - torrent::PollSelect* p = torrent::PollSelect::create(maxOpenSockets); - - if (p == NULL) - return NULL; - - return new PollManagerSelect(p); -} - -PollManagerSelect::~PollManagerSelect() { -} - -void -PollManagerSelect::poll(rak::timer timeout) { - // timeout = std::min(timeout, rak::timer(torrent::next_timeout())) + 1000; - - static_cast(m_poll)->do_poll(timeout.usec()); -} - -void -PollManagerSelect::poll_simple(rak::timer timeout) { - static_cast(m_poll)->do_poll(timeout.usec(), torrent::PollSelect::poll_worker_thread); -} - -} diff --git a/src/core/poll_manager_select.h b/src/core/poll_manager_select.h deleted file mode 100644 index 18082360..00000000 --- a/src/core/poll_manager_select.h +++ /dev/null @@ -1,64 +0,0 @@ -// 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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_CORE_POLL_MANAGER_SELECT_H -#define RTORRENT_CORE_POLL_MANAGER_SELECT_H - -#include "poll_manager.h" - -namespace torrent { - class PollSelect; -} - -namespace core { - -class lt_cacheline_aligned PollManagerSelect : public PollManager { -public: - static PollManagerSelect* create(int maxOpenSockets); - ~PollManagerSelect(); - - void poll(rak::timer timeout); - void poll_simple(rak::timer timeout); - -private: - PollManagerSelect(torrent::Poll* p); - - unsigned int m_setSize; -}; - -} - -#endif diff --git a/src/thread_base.cc b/src/thread_base.cc index 4996e223..7080f8b0 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -107,15 +107,13 @@ public: void throw_shutdown_exception() { throw torrent::shutdown_exception(); } -ThreadBase::ThreadBase() : - m_pollManager(NULL) { +ThreadBase::ThreadBase() { m_taskShutdown.set_slot(rak::ptr_fn(&throw_shutdown_exception)); m_threadQueue = new thread_queue_hack; } ThreadBase::~ThreadBase() { - delete m_pollManager; delete m_threadQueue; } @@ -155,7 +153,7 @@ ThreadBase::event_loop(ThreadBase* thread) { rak::priority_queue_perform(&thread->m_taskScheduler, cachedTime); - thread->m_pollManager->poll_simple(thread->client_next_timeout()); + thread->m_poll->do_poll(thread->client_next_timeout().usec(), torrent::Poll::poll_worker_thread); } } catch (torrent::shutdown_exception& e) { diff --git a/src/thread_base.h b/src/thread_base.h index 5ac89ee2..201a02bb 100644 --- a/src/thread_base.h +++ b/src/thread_base.h @@ -90,7 +90,6 @@ protected: // The timer needs to be sync'ed when updated... - core::PollManager* m_pollManager; rak::priority_queue_default m_taskScheduler; rak::priority_item m_taskShutdown; diff --git a/src/thread_main.cc b/src/thread_main.cc index d41997b7..47ffa25f 100644 --- a/src/thread_main.cc +++ b/src/thread_main.cc @@ -49,9 +49,8 @@ ThreadMain::init_thread() { // The main thread always holds the lock while running. acquire_global_lock(); - m_pollManager = core::PollManager::create_poll_manager(); - m_pollManager->get_torrent_poll()->set_flags(torrent::Poll::flag_waive_global_lock); - m_poll = m_pollManager->get_torrent_poll(); + m_poll = core::create_poll(); + m_poll->set_flags(torrent::Poll::flag_waive_global_lock); m_state = STATE_INITIALIZED; m_thread = pthread_self(); diff --git a/src/thread_worker.cc b/src/thread_worker.cc index e955e10e..c25a994a 100644 --- a/src/thread_worker.cc +++ b/src/thread_worker.cc @@ -62,9 +62,7 @@ ThreadWorker::~ThreadWorker() { void ThreadWorker::init_thread() { - m_pollManager = core::PollManager::create_poll_manager(); - m_poll = m_pollManager->get_torrent_poll(); - + m_poll = core::create_poll(); m_state = STATE_INITIALIZED; }