diff --git a/include/libtorrent/http_seed_connection.hpp b/include/libtorrent/http_seed_connection.hpp index 0e2f80de0..a3ca52cc7 100644 --- a/include/libtorrent/http_seed_connection.hpp +++ b/include/libtorrent/http_seed_connection.hpp @@ -97,6 +97,7 @@ namespace libtorrent , tcp::endpoint const& remote , std::string const& url , policy::peer* peerinfo); + void start(); ~http_seed_connection(); diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index 8d8b1fb99..2d357b787 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -97,6 +97,7 @@ namespace libtorrent , tcp::endpoint const& remote , std::string const& url , policy::peer* peerinfo); + void start(); ~web_peer_connection(); diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index 48395247b..19ece4d74 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -72,7 +72,6 @@ namespace libtorrent // we want large blocks as well, so // we can request more bytes at once request_large_blocks(true); - set_upload_only(true); prefer_whole_pieces(1); // we only want left-over bandwidth @@ -106,6 +105,13 @@ namespace libtorrent m_server_string += m_host; } + void http_seed_connection::start() + { + set_upload_only(true); + if (is_disconnecting()) return; + peer_connection::start(); + } + http_seed_connection::~http_seed_connection() {} diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 7d44747a6..9dab8b2d6 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1574,6 +1574,8 @@ namespace libtorrent void peer_connection::disconnect_if_redundant() { + // we cannot disconnect in a constructor + TORRENT_ASSERT(m_in_constructor == false); if (!m_ses.settings().close_redundant_connections) return; boost::shared_ptr t = m_torrent.lock(); @@ -2283,6 +2285,10 @@ namespace libtorrent boost::shared_ptr t = m_torrent.lock(); TORRENT_ASSERT(t); + // we cannot disconnect in a constructor, and + // this function may end up doing that + TORRENT_ASSERT(m_in_constructor == false); + #ifdef TORRENT_VERBOSE_LOGGING (*m_logger) << time_now_string() << " <== HAVE_ALL\n"; #endif @@ -2713,6 +2719,10 @@ namespace libtorrent void peer_connection::send_not_interested() { + // we cannot disconnect in a constructor, and + // this function may end up doing that + TORRENT_ASSERT(m_in_constructor == false); + if (!m_interesting) { disconnect_if_redundant(); diff --git a/src/web_peer_connection.cpp b/src/web_peer_connection.cpp index 6986e0818..80298735c 100644 --- a/src/web_peer_connection.cpp +++ b/src/web_peer_connection.cpp @@ -73,7 +73,6 @@ namespace libtorrent // we want large blocks as well, so // we can request more bytes at once request_large_blocks(true); - set_upload_only(true); // we only want left-over bandwidth set_priority(1); @@ -110,6 +109,13 @@ namespace libtorrent m_server_string += m_host; } + void web_peer_connection::start() + { + set_upload_only(true); + if (is_disconnecting()) return; + peer_connection::start(); + } + web_peer_connection::~web_peer_connection() {}