diff --git a/Makefile.am b/Makefile.am index 794f2add..219b5a71 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ SUBDIRS = \ test EXTRA_DIST= \ + rtorrent.lua \ rak/address_info.h \ rak/algorithm.h \ rak/allocators.h \ diff --git a/scripts/checks.m4 b/scripts/checks.m4 index 4187e1de..ed5a49e2 100644 --- a/scripts/checks.m4 +++ b/scripts/checks.m4 @@ -88,49 +88,11 @@ AC_DEFUN([TORRENT_CHECK_KQUEUE], [ [ AC_DEFINE(USE_KQUEUE, 1, Use kqueue.) AC_MSG_RESULT(yes) - TORRENT_CHECK_KQUEUE_SOCKET_ONLY ], [ AC_MSG_RESULT(no) ]) ]) -AC_DEFUN([TORRENT_CHECK_KQUEUE_SOCKET_ONLY], [ - AC_MSG_CHECKING(whether kqueue supports pipes and ptys) - - AC_LINK_IFELSE([AC_LANG_SOURCE([ - #include - #include - #include - #include - #include - int main() { - struct kevent ev@<:@2@:>@, ev_out@<:@2@:>@; - struct timespec ts = { 0, 0 }; - int pfd@<:@2@:>@, pty@<:@2@:>@, kfd, n; - char buffer@<:@9001@:>@; - if (pipe(pfd) == -1) return 1; - if (fcntl(pfd@<:@1@:>@, F_SETFL, O_NONBLOCK) == -1) return 2; - while ((n = write(pfd@<:@1@:>@, buffer, sizeof(buffer))) == sizeof(buffer)); - if ((pty@<:@0@:>@=posix_openpt(O_RDWR | O_NOCTTY)) == -1) return 3; - if ((pty@<:@1@:>@=grantpt(pty@<:@0@:>@)) == -1) return 4; - EV_SET(ev+0, pfd@<:@1@:>@, EVFILT_WRITE, EV_ADD | EV_ENABLE, 0, 0, NULL); - EV_SET(ev+1, pty@<:@1@:>@, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, NULL); - if ((kfd = kqueue()) == -1) return 5; - if ((n = kevent(kfd, ev, 2, NULL, 0, NULL)) == -1) return 6; - if (ev_out@<:@0@:>@.flags & EV_ERROR) return 7; - if (ev_out@<:@1@:>@.flags & EV_ERROR) return 8; - read(pfd@<:@0@:>@, buffer, sizeof(buffer)); - if ((n = kevent(kfd, NULL, 0, ev_out, 2, &ts)) < 1) return 9; - return 0; - } - ])], - [ - AC_MSG_RESULT(yes) - ], [ - AC_DEFINE(KQUEUE_SOCKET_ONLY, 1, kqueue only supports sockets.) - AC_MSG_RESULT(no) - ]) -]) AC_DEFUN([TORRENT_WITH_KQUEUE], [ AC_ARG_WITH(kqueue, diff --git a/src/Makefile.am b/src/Makefile.am index f6861c9f..4b6f2666 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,8 +26,6 @@ libsub_root_a_SOURCES = \ core/http_queue.h \ core/manager.cc \ core/manager.h \ - core/poll_manager.cc \ - core/poll_manager.h \ core/range_map.h \ core/view.cc \ core/view.h \ diff --git a/src/command_network.cc b/src/command_network.cc index 0c49ebf5..22662462 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -15,6 +15,7 @@ #include #include +#include "core/curl_stack.h" #include "core/download.h" #include "core/manager.h" #include "rpc/scgi.h" diff --git a/src/control.cc b/src/control.cc index be2f11c5..b5cf231e 100644 --- a/src/control.cc +++ b/src/control.cc @@ -5,12 +5,12 @@ #include #include -#include "core/manager.h" -#include "core/download_store.h" -#include "core/view_manager.h" +#include "core/curl_stack.h" #include "core/dht_manager.h" +#include "core/download_store.h" #include "core/http_queue.h" - +#include "core/manager.h" +#include "core/view_manager.h" #include "display/canvas.h" #include "display/window.h" #include "display/window_http_queue.h" diff --git a/src/core/manager.cc b/src/core/manager.cc index cf1fe730..91536337 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -28,13 +28,13 @@ #include "globals.h" #include "curl_get.h" +#include "curl_stack.h" #include "control.h" #include "download.h" #include "download_factory.h" #include "download_store.h" #include "http_queue.h" #include "manager.h" -#include "poll_manager.h" #include "view.h" namespace core { @@ -261,7 +261,7 @@ Manager::set_local_address(const std::string& addr) { if ((err = rak::address_info::get_address_info(addr.c_str(), PF_INET, SOCK_STREAM, &ai)) != 0 && (err = rak::address_info::get_address_info(addr.c_str(), PF_INET6, SOCK_STREAM, &ai)) != 0) throw torrent::input_error("Could not set local address: " + std::string(rak::address_info::strerror(err)) + "."); - + try { torrent::connection_manager()->set_local_address(ai->address()->c_sockaddr()); @@ -283,9 +283,9 @@ Manager::set_proxy_address(const std::string& addr) { int port; rak::address_info* ai; - char buf[addr.length() + 1]; + std::string buf(addr.length() + 1, '\0'); - int err = std::sscanf(addr.c_str(), "%[^:]:%i", buf, &port); + int err = std::sscanf(addr.c_str(), "%[^:]:%i", buf.data(), &port); if (err <= 0) throw torrent::input_error("Could not parse proxy address."); @@ -293,7 +293,7 @@ Manager::set_proxy_address(const std::string& addr) { if (err == 1) port = 80; - if ((err = rak::address_info::get_address_info(buf, PF_INET, SOCK_STREAM, &ai)) != 0) + if ((err = rak::address_info::get_address_info(buf.data(), PF_INET, SOCK_STREAM, &ai)) != 0) throw torrent::input_error("Could not set proxy address: " + std::string(rak::address_info::strerror(err)) + "."); try { diff --git a/src/core/manager.h b/src/core/manager.h index 21833c1f..f6567f3a 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -10,7 +10,6 @@ #include #include "download_list.h" -#include "poll_manager.h" #include "range_map.h" namespace torrent { @@ -23,6 +22,7 @@ class FileStatusCache; namespace core { +class CurlStack; class DownloadStore; class HttpQueue; diff --git a/src/core/poll_manager.cc b/src/core/poll_manager.cc deleted file mode 100644 index 1a3a0a51..00000000 --- a/src/core/poll_manager.cc +++ /dev/null @@ -1,91 +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 "globals.h" -#include "control.h" -#include "manager.h" -#include "poll_manager.h" - -namespace core { - -torrent::Poll* -create_poll() { - const char* poll_name = getenv("RTORRENT_POLL"); - - int maxOpen = sysconf(_SC_OPEN_MAX); - - torrent::Poll* poll = NULL; - - 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) - control->core()->push_log_std(std::string("Cannot enable '") + poll_name + "' based polling."); - } - - if (poll != NULL) - control->core()->push_log_std(std::string("Using '") + poll_name + "' based polling."); - - else if ((poll = torrent::PollEPoll::create(maxOpen)) != NULL) - control->core()->push_log_std("Using 'epoll' based polling."); - - else if ((poll = torrent::PollKQueue::create(maxOpen)) != NULL) - control->core()->push_log_std("Using 'kqueue' based polling."); - - else if ((poll = torrent::PollSelect::create(maxOpen)) != NULL) - control->core()->push_log_std("Using 'select' based polling."); - - else - throw torrent::internal_error("Could not create any Poll object."); - - return poll; -} - -} diff --git a/src/core/poll_manager.h b/src/core/poll_manager.h deleted file mode 100644 index bdbf5a0e..00000000 --- a/src/core/poll_manager.h +++ /dev/null @@ -1,52 +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_H -#define RTORRENT_CORE_POLL_MANAGER_H - -#include "curl_stack.h" - -namespace torrent { -class Poll; -} - -namespace core { - -torrent::Poll* create_poll(); - -} - -#endif diff --git a/src/display/utils.cc b/src/display/utils.cc index c5bbaff8..b102ce77 100644 --- a/src/display/utils.cc +++ b/src/display/utils.cc @@ -17,6 +17,7 @@ #include #include +#include "core/curl_stack.h" #include "core/download.h" #include "core/manager.h" #include "rpc/parse_commands.h" diff --git a/src/main.cc b/src/main.cc index 2ff07b2d..ee77359c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -132,6 +132,16 @@ client_perform() { control->inc_tick(); } +torrent::Poll* +create_poll() { + torrent::Poll* poll = torrent::Poll::create(sysconf(_SC_OPEN_MAX)); + + if (poll == nullptr) + throw torrent::internal_error("Unable to create poll object: " + std::string(std::strerror(errno))); + + return poll; +} + int main(int argc, char** argv) { try { @@ -178,7 +188,7 @@ main(int argc, char** argv) { torrent::log_add_group_output(torrent::LOG_NOTICE, "important"); torrent::log_add_group_output(torrent::LOG_INFO, "complete"); - torrent::Poll::slot_create_poll() = std::bind(&core::create_poll); + torrent::Poll::slot_create_poll() = [](){ return create_poll(); }; torrent::initialize(); torrent::set_main_thread_slots(std::bind(&client_perform)); diff --git a/src/thread_worker.cc b/src/thread_worker.cc index 827f4726..8da3242a 100644 --- a/src/thread_worker.cc +++ b/src/thread_worker.cc @@ -22,7 +22,7 @@ ThreadWorker::~ThreadWorker() { void ThreadWorker::init_thread() { - m_poll = std::unique_ptr(core::create_poll()); + m_poll = std::unique_ptr(torrent::Poll::slot_create_poll()()); m_state = STATE_INITIALIZED; }