*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-01-20 11:01:50 +00:00
parent 3d39c3ddd4
commit 6d22d4144c
7 changed files with 58 additions and 19 deletions

View File

@ -238,6 +238,12 @@ namespace libtorrent
const peer_id& get_peer_id() const { return m_peer_id; }
const std::vector<bool>& get_bitfield() const { return m_have_piece; }
// this will cause this peer_connection to be disconnected.
// what it does is that it puts a reference to it in
// m_ses.m_disconnect_peer list, which will be scanned in the
// mainloop to disconnect peers.
void disconnect();
// sets the number of bytes this peer
// is allowed to send until it should
// stop sending. When it stops sending

View File

@ -156,8 +156,18 @@ namespace libtorrent
tracker_manager m_tracker_manager;
std::map<sha1_hash, boost::shared_ptr<torrent> > m_torrents;
// this maps sockets to their peer_connection
// object. It is the complete list of all connected
// peers.
connection_map m_connections;
// this is a list of iterators into the m_connections map
// that should be disconnected as soon as possible.
// It is used to delay disconnections to avoid troubles
// in loops that iterate over them.
std::vector<connection_map::iterator> m_disconnect_peer;
// the peer id that is generated at the start of each torrent
peer_id m_peer_id;
@ -191,6 +201,10 @@ namespace libtorrent
// NAT or not.
bool m_incoming_connection;
// does the actual disconnections
// that are queued up in m_disconnect_peer
void purge_connections();
#ifndef NDEBUG
void assert_invariant(int marker = -1);
boost::shared_ptr<logger> create_log(std::string name);

View File

@ -210,6 +210,7 @@ namespace libtorrent
void announce_piece(int index);
void close_all_connections();
void disconnect_seeds();
piece_picker& picker() { return m_picker; }

View File

@ -43,6 +43,8 @@ namespace
{
char buffer[1024];
int err = GetLastError();
// TODO: can this be done in an exception safe AND
// buffer overrun-safe way?
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0, buffer, 0, 0);
std::stringstream s;
s << thrower << ": " << buffer;

View File

@ -693,8 +693,6 @@ namespace libtorrent
if (verified)
{
m_torrent->announce_piece(p.piece);
// TODO: if we bacame a seed, disconnect
// from all seeds
}
else
{
@ -711,6 +709,8 @@ namespace libtorrent
m_torrent->get_handle()
, "torrent is finished downloading"));
}
m_torrent->disconnect_seeds();
}
}
@ -866,8 +866,13 @@ namespace libtorrent
void peer_connection::disconnect()
{
detail::session_impl::connection_map::iterator i = m_ses.m_connections.find(m_socket);
assert(i != m_ses.m_connections.end());
assert(std::find(m_ses.m_disconnect_peer.begin(), m_ses.m_disconnect_peer.end(), i) == m_ses.m_disconnect_peer.end());
m_ses.m_disconnect_peer.push_back(i);
}
bool peer_connection::dispatch_message(int received)
{

View File

@ -372,6 +372,14 @@ namespace libtorrent
}
}
void session_impl::purge_connections()
{
while (!m_disconnect_peer.empty())
{
m_connections.erase(m_disconnect_peer.back());
m_disconnect_peer.pop_back();
}
}
void session_impl::operator()()
{
@ -501,6 +509,7 @@ namespace libtorrent
}
}
}
purge_connections();
#ifndef NDEBUG
assert_invariant();
@ -568,7 +577,7 @@ namespace libtorrent
}
}
}
purge_connections();
#ifndef NDEBUG
assert_invariant();
#endif
@ -658,6 +667,8 @@ namespace libtorrent
i->second->second_tick();
++i;
}
purge_connections();
// distribute the maximum upload rate among the peers
control_upload_rates(m_upload_rate, m_connections);

View File

@ -637,23 +637,23 @@ namespace libtorrent
void torrent::close_all_connections()
{
for (peer_iterator i = m_connections.begin();
i != m_connections.end();)
i != m_connections.end();
++i)
{
assert(i->second->associated_torrent() == this);
i->second->disconnect();
}
}
detail::session_impl::connection_map::iterator j =
m_ses.m_connections.find(i->second->get_socket());
assert(j != m_ses.m_connections.end());
// in the destructor of the peer_connection
// it will remove itself from this torrent
// and from the list we're iterating over.
// so we need to increment the iterator riht
// away.
++i;
m_ses.m_connections.erase(j);
void torrent::disconnect_seeds()
{
for (peer_iterator i = m_connections.begin();
i != m_connections.end();
++i)
{
assert(i->second->associated_torrent() == this);
if (i->second->is_seed())
i->second->disconnect();
}
}