removed calls to self() from inside constructors in peer connections
This commit is contained in:
parent
4328326ca1
commit
1511f2f59b
|
@ -102,6 +102,8 @@ namespace libtorrent
|
||||||
, boost::shared_ptr<socket_type> s
|
, boost::shared_ptr<socket_type> s
|
||||||
, policy::peer* peerinfo);
|
, policy::peer* peerinfo);
|
||||||
|
|
||||||
|
void start();
|
||||||
|
|
||||||
~bt_peer_connection();
|
~bt_peer_connection();
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
|
|
|
@ -122,6 +122,12 @@ namespace libtorrent
|
||||||
, boost::shared_ptr<socket_type> s
|
, boost::shared_ptr<socket_type> s
|
||||||
, policy::peer* peerinfo);
|
, policy::peer* peerinfo);
|
||||||
|
|
||||||
|
// this function is called after it has been constructed and properly
|
||||||
|
// reference counted. It is safe to call self() in this function
|
||||||
|
// and schedule events with references to itself (that is not safe to
|
||||||
|
// do in the constructor).
|
||||||
|
virtual void start();
|
||||||
|
|
||||||
virtual ~peer_connection();
|
virtual ~peer_connection();
|
||||||
|
|
||||||
void set_peer_info(policy::peer* pi)
|
void set_peer_info(policy::peer* pi)
|
||||||
|
@ -515,6 +521,14 @@ namespace libtorrent
|
||||||
char m_country[2];
|
char m_country[2];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
boost::intrusive_ptr<peer_connection> self()
|
||||||
|
{
|
||||||
|
TORRENT_ASSERT(!m_in_constructor);
|
||||||
|
return intrusive_ptr_base<peer_connection>::self();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void fill_send_buffer();
|
void fill_send_buffer();
|
||||||
|
|
|
@ -163,13 +163,19 @@ namespace libtorrent
|
||||||
m_bandwidth_limit[upload_channel].assign(80);
|
m_bandwidth_limit[upload_channel].assign(80);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
m_in_constructor = false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void bt_peer_connection::start()
|
||||||
|
{
|
||||||
|
peer_connection::start();
|
||||||
|
|
||||||
// start in the state where we are trying to read the
|
// start in the state where we are trying to read the
|
||||||
// handshake from the other side
|
// handshake from the other side
|
||||||
reset_recv_buffer(20);
|
reset_recv_buffer(20);
|
||||||
setup_receive();
|
setup_receive();
|
||||||
#ifndef NDEBUG
|
|
||||||
m_in_constructor = false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_peer_connection::~bt_peer_connection()
|
bt_peer_connection::~bt_peer_connection()
|
||||||
|
|
|
@ -140,12 +140,7 @@ namespace libtorrent
|
||||||
piece_failed = false;
|
piece_failed = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
|
||||||
TORRENT_ASSERT(t);
|
|
||||||
std::fill(m_peer_id.begin(), m_peer_id.end(), 0);
|
std::fill(m_peer_id.begin(), m_peer_id.end(), 0);
|
||||||
|
|
||||||
if (t->ready_for_connections())
|
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// incoming connection
|
// incoming connection
|
||||||
|
@ -269,6 +264,14 @@ namespace libtorrent
|
||||||
m_downloaded_at_last_unchoke = m_statistics.total_payload_download();
|
m_downloaded_at_last_unchoke = m_statistics.total_payload_download();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void peer_connection::start()
|
||||||
|
{
|
||||||
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||||
|
|
||||||
|
if (t && t->ready_for_connections())
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
void peer_connection::update_interest()
|
void peer_connection::update_interest()
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
|
@ -720,7 +720,11 @@ namespace aux {
|
||||||
c->m_in_constructor = false;
|
c->m_in_constructor = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!c->is_disconnecting()) m_connections.insert(c);
|
if (!c->is_disconnecting())
|
||||||
|
{
|
||||||
|
m_connections.insert(c);
|
||||||
|
c->start();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& exc)
|
catch (std::exception& exc)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2047,6 +2047,7 @@ namespace libtorrent
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
c->m_in_constructor = false;
|
c->m_in_constructor = false;
|
||||||
#endif
|
#endif
|
||||||
|
c->start();
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
for (extension_list_t::iterator i = m_extensions.begin()
|
for (extension_list_t::iterator i = m_extensions.begin()
|
||||||
|
@ -2365,6 +2366,7 @@ namespace libtorrent
|
||||||
// add the newly connected peer to this torrent's peer list
|
// add the newly connected peer to this torrent's peer list
|
||||||
m_connections.insert(boost::get_pointer(c));
|
m_connections.insert(boost::get_pointer(c));
|
||||||
m_ses.m_connections.insert(c);
|
m_ses.m_connections.insert(c);
|
||||||
|
c->start();
|
||||||
|
|
||||||
int timeout = settings().peer_connect_timeout;
|
int timeout = settings().peer_connect_timeout;
|
||||||
if (peerinfo) timeout += 3 * peerinfo->failcount;
|
if (peerinfo) timeout += 3 * peerinfo->failcount;
|
||||||
|
|
Loading…
Reference in New Issue