properly back off when accept() returns EMFILE

This commit is contained in:
Arvid Norberg 2011-03-23 08:49:26 +00:00
parent f93988e11e
commit 1ab853db40
1 changed files with 14 additions and 1 deletions

View File

@ -2165,7 +2165,20 @@ namespace aux {
// and lower the number of file descriptors used
// elsewere.
if (m_settings.connections_limit > 10)
--m_settings.connections_limit;
{
// now, disconnect a random peer
torrent_map::iterator i = std::max_element(m_torrents.begin()
, m_torrents.end(), boost::bind(&torrent::num_peers
, boost::bind(&torrent_map::value_type::second, _1)));
if (i != m_torrents.end())
{
error_code ec;
i->second->disconnect_peers(1, ec);
}
m_settings.connections_limit = m_connections.size();
}
// try again, but still alert the user of the problem
async_accept(listener);
}