From ee859a61375ad3919ebab41b730b6edcdaaeb21a Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 12 Dec 2011 03:32:36 +0900 Subject: [PATCH] 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; }