diff --git a/src/command_download.cc b/src/command_download.cc index e0008576..574a5dab 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -1,8 +1,9 @@ #include "config.h" -#include -#include #include +#include +#include +#include #include #include #include @@ -19,6 +20,8 @@ #include #include #include +#include +#include #include #include #include @@ -283,21 +286,6 @@ retrieve_d_bitfield(core::Download* download) { return torrent::Object(rak::transform_hex(bitField->begin(), bitField->end())); } -struct call_add_d_peer_t { - call_add_d_peer_t(core::Download* d, int port) : m_download(d), m_port(port) { } - - void operator() (const sockaddr* sa, [[maybe_unused]] int err) { - if (sa == NULL) { - lt_log_print(torrent::LOG_TORRENT_WARN, "could not resolve hostname for added peer"); - } else { - m_download->download()->add_peer(sa, m_port); - } - } - - core::Download* m_download; - int m_port; -}; - void apply_d_add_peer(core::Download* download, const std::string& arg) { int port, ret; @@ -320,7 +308,15 @@ apply_d_add_peer(core::Download* download, const std::string& arg) { if (port < 1 || port > 65535) throw torrent::input_error("Invalid port number."); - torrent::connection_manager()->resolver()(host, (int)rak::socket_address::pf_unspec, SOCK_STREAM, call_add_d_peer_t(download, port)); + // Currently discarding SOCK_STREAM. + torrent::main_thread()->resolver()->resolve_preferred(NULL, host, AF_UNSPEC, AF_INET, [download, port](torrent::c_sa_shared_ptr sa, int err) { + if (sa == nullptr) { + lt_log_print(torrent::LOG_TORRENT_WARN, "could not resolve hostname for added peer: %s", gai_strerror(err)); + return; + } + + download->download()->add_peer(sa.get(), port); + }); } torrent::Object diff --git a/src/command_tracker.cc b/src/command_tracker.cc index add7d050..e7f75727 100644 --- a/src/command_tracker.cc +++ b/src/command_tracker.cc @@ -1,8 +1,10 @@ #include "config.h" #include +#include #include #include +#include #include #include #include @@ -23,20 +25,6 @@ tracker_set_enabled(torrent::tracker::Tracker* tracker, bool state) { tracker->disable(); } -struct call_add_node_t { - call_add_node_t(int port) : m_port(port) { } - - void operator() (const sockaddr* sa, [[maybe_unused]] int err) { - if (sa == NULL) { - lt_log_print(torrent::LOG_DHT_WARN, "Could not resolve host."); - } else { - torrent::dht_controller()->add_node(sa, m_port); - } - } - - int m_port; -}; - torrent::Object apply_dht_add_node(const std::string& arg) { if (!torrent::dht_controller()->is_valid()) @@ -56,7 +44,16 @@ apply_dht_add_node(const std::string& arg) { if (port < 1 || port > 65535) throw torrent::input_error("Invalid port number."); - torrent::connection_manager()->resolver()(host, (int)rak::socket_address::pf_inet, SOCK_DGRAM, call_add_node_t(port)); + // Currently discarding SOCK_STREAM. + torrent::main_thread()->resolver()->resolve_specific(nullptr, host, PF_INET, [port](torrent::c_sa_shared_ptr sa, int err) { + if (sa == nullptr) { + lt_log_print(torrent::LOG_DHT_WARN, "Could not resolve host: %s", gai_strerror(err)); + return; + } + + torrent::dht_controller()->add_node(sa.get(), port); + }); + return torrent::Object(); } diff --git a/src/thread_base.cc b/src/thread_base.cc index c8d45a3f..e5bceaaf 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -91,6 +91,8 @@ ThreadBase::call_events() { call_queued_items(); rak::priority_queue_perform(&m_taskScheduler, cachedTime); + + process_callbacks(); } void diff --git a/src/thread_worker.cc b/src/thread_worker.cc index 4e4f0c7e..abae1fde 100644 --- a/src/thread_worker.cc +++ b/src/thread_worker.cc @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent library -// 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 "thread_worker.h" @@ -45,14 +9,12 @@ #include #include #include +#include #include "core/manager.h" #include "rpc/scgi.h" #include "rpc/parse_commands.h" -ThreadWorker::ThreadWorker() { -} - ThreadWorker::~ThreadWorker() { if (m_scgi) m_scgi.load()->deactivate(); @@ -60,7 +22,7 @@ ThreadWorker::~ThreadWorker() { void ThreadWorker::init_thread() { - m_poll = core::create_poll(); + m_poll = std::unique_ptr(core::create_poll()); m_state = STATE_INITIALIZED; } diff --git a/src/thread_worker.h b/src/thread_worker.h index d0e0754e..dfb5820b 100644 --- a/src/thread_worker.h +++ b/src/thread_worker.h @@ -1,46 +1,10 @@ -// rTorrent - BitTorrent library -// 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_THREAD_WORKER_H #define RTORRENT_THREAD_WORKER_H #include -#include "thread_base.h" -#include +#include "thread_base.h" +#include "rak/priority_queue_default.h" namespace rpc { class SCgi; @@ -49,9 +13,9 @@ class SCgi; // Check if cacheline aligned with inheritance ends up taking two // cachelines. -class lt_cacheline_aligned ThreadWorker : public ThreadBase { +class ThreadWorker : public ThreadBase { public: - ThreadWorker(); + ThreadWorker() = default; ~ThreadWorker(); const char* name() const { return "rtorrent scgi"; } @@ -60,7 +24,7 @@ public: rpc::SCgi* scgi() { return m_scgi; } bool set_scgi(rpc::SCgi* scgi); - + void set_rpc_log(const std::string& filename); static void start_scgi(ThreadBase* thread);