diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 7648c7c02..04da09bf9 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -476,7 +476,7 @@ namespace aux { port_filter const& get_port_filter() const override; void ban_ip(address addr) override; - void queue_tracker_request(tracker_request& req + void queue_tracker_request(tracker_request&& req , std::weak_ptr c) override; // ==== peer class operations ==== diff --git a/include/libtorrent/aux_/session_interface.hpp b/include/libtorrent/aux_/session_interface.hpp index 3c7f6815e..b7a70634f 100644 --- a/include/libtorrent/aux_/session_interface.hpp +++ b/include/libtorrent/aux_/session_interface.hpp @@ -233,8 +233,11 @@ namespace aux { virtual void apply_settings_pack(std::shared_ptr pack) = 0; virtual session_settings const& settings() const = 0; - virtual void queue_tracker_request(tracker_request& req + // the tracker request object must be moved in + virtual void queue_tracker_request(tracker_request&& req , std::weak_ptr c) = 0; + void queue_tracker_request(tracker_request const& req + , std::weak_ptr c) = delete; // peer-classes virtual void set_peer_classes(peer_class_set* s, address const& a, int st) = 0; diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index e2192d3be..0b5a0f6be 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -357,9 +357,14 @@ namespace libtorrent { void queue_request( io_service& ios - , tracker_request r + , tracker_request&& r , std::weak_ptr c = std::weak_ptr()); + void queue_request( + io_service& ios + , tracker_request const& r + , std::weak_ptr c + = std::weak_ptr()) = delete; void abort_all_requests(bool all = false); void remove_request(http_tracker_connection const* c); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4558f8590..72ac186c8 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1035,7 +1035,7 @@ namespace aux { return ret; } - void session_impl::queue_tracker_request(tracker_request& req + void session_impl::queue_tracker_request(tracker_request&& req , std::weak_ptr c) { #if TORRENT_USE_I2P @@ -1062,7 +1062,7 @@ namespace aux { use_ssl ? ssl_listen_port(ls) : #endif listen_port(ls); - m_tracker_manager.queue_request(get_io_service(), req, c); + m_tracker_manager.queue_request(get_io_service(), std::move(req), c); } else { @@ -1071,7 +1071,8 @@ namespace aux { #ifdef TORRENT_USE_OPENSSL if ((ls->ssl == transport::ssl) != use_ssl) continue; #endif - req.listen_port = + tracker_request socket_req(req); + socket_req.listen_port = #ifdef TORRENT_USE_OPENSSL // SSL torrents use the SSL listen port use_ssl ? ssl_listen_port(ls.get()) : @@ -1080,9 +1081,9 @@ namespace aux { // we combine the per-torrent key with the per-interface key to make // them consistent and unique per torrent and interface - req.key ^= ls->tracker_key; - req.outgoing_socket = ls; - m_tracker_manager.queue_request(get_io_service(), req, c); + socket_req.key ^= ls->tracker_key; + socket_req.outgoing_socket = ls; + m_tracker_manager.queue_request(get_io_service(), std::move(socket_req), c); } } } diff --git a/src/torrent.cpp b/src/torrent.cpp index b0869bed4..9029861a4 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2919,12 +2919,12 @@ bool is_downloading_state(int const st) if (m_abort && m_ses.should_log()) { auto tl = std::make_shared(m_ses); - m_ses.queue_tracker_request(req, tl); + m_ses.queue_tracker_request(tracker_request(req), tl); } else #endif { - m_ses.queue_tracker_request(req, shared_from_this()); + m_ses.queue_tracker_request(tracker_request(req), shared_from_this()); } aep.updating = true; @@ -2979,7 +2979,7 @@ bool is_downloading_state(int const st) #endif req.key = tracker_key(); req.triggered_manually = user_triggered; - m_ses.queue_tracker_request(req, shared_from_this()); + m_ses.queue_tracker_request(std::move(req), shared_from_this()); } void torrent::tracker_warning(tracker_request const& req, std::string const& msg) diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 1f519c9cb..415ecf6be 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -256,7 +256,7 @@ namespace libtorrent { void tracker_manager::queue_request( io_service& ios - , tracker_request req + , tracker_request&& req , std::weak_ptr c) { TORRENT_ASSERT(is_single_thread()); @@ -278,14 +278,14 @@ namespace libtorrent { if (protocol == "http") #endif { - auto con = std::make_shared(ios, *this, req, c); + auto con = std::make_shared(ios, *this, std::move(req), c); m_http_conns.push_back(con); con->start(); return; } else if (protocol == "udp") { - auto con = std::make_shared(ios, *this, req, c); + auto con = std::make_shared(ios, *this, std::move(req), c); m_udp_conns[con->transaction_id()] = con; con->start(); return; @@ -293,7 +293,7 @@ namespace libtorrent { // we need to post the error to avoid deadlock if (std::shared_ptr r = c.lock()) - ios.post(std::bind(&request_callback::tracker_request_error, r, req + ios.post(std::bind(&request_callback::tracker_request_error, r, std::move(req) , error_code(errors::unsupported_url_protocol) , "", seconds32(0))); }