removed calls to self() from inside constructors in peer connections

This commit is contained in:
Arvid Norberg 2008-03-31 04:46:24 +00:00
parent 4328326ca1
commit 1511f2f59b
6 changed files with 40 additions and 9 deletions

View File

@ -102,6 +102,8 @@ namespace libtorrent
, boost::shared_ptr<socket_type> s
, policy::peer* peerinfo);
void start();
~bt_peer_connection();
#ifndef TORRENT_DISABLE_ENCRYPTION

View File

@ -122,6 +122,12 @@ namespace libtorrent
, boost::shared_ptr<socket_type> s
, 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();
void set_peer_info(policy::peer* pi)
@ -515,6 +521,14 @@ namespace libtorrent
char m_country[2];
#endif
#ifndef NDEBUG
boost::intrusive_ptr<peer_connection> self()
{
TORRENT_ASSERT(!m_in_constructor);
return intrusive_ptr_base<peer_connection>::self();
}
#endif
private:
void fill_send_buffer();

View File

@ -163,13 +163,19 @@ namespace libtorrent
m_bandwidth_limit[upload_channel].assign(80);
#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
// handshake from the other side
reset_recv_buffer(20);
setup_receive();
#ifndef NDEBUG
m_in_constructor = false;
#endif
}
bt_peer_connection::~bt_peer_connection()

View File

@ -140,12 +140,7 @@ namespace libtorrent
piece_failed = false;
#endif
boost::shared_ptr<torrent> t = m_torrent.lock();
TORRENT_ASSERT(t);
std::fill(m_peer_id.begin(), m_peer_id.end(), 0);
if (t->ready_for_connections())
init();
}
// incoming connection
@ -269,6 +264,14 @@ namespace libtorrent
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()
{
INVARIANT_CHECK;

View File

@ -720,7 +720,11 @@ namespace aux {
c->m_in_constructor = false;
#endif
if (!c->is_disconnecting()) m_connections.insert(c);
if (!c->is_disconnecting())
{
m_connections.insert(c);
c->start();
}
}
catch (std::exception& exc)
{

View File

@ -2047,6 +2047,7 @@ namespace libtorrent
#ifndef NDEBUG
c->m_in_constructor = false;
#endif
c->start();
#ifndef TORRENT_DISABLE_EXTENSIONS
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
m_connections.insert(boost::get_pointer(c));
m_ses.m_connections.insert(c);
c->start();
int timeout = settings().peer_connect_timeout;
if (peerinfo) timeout += 3 * peerinfo->failcount;