forked from premiere/premiere-libtorrent
exception related fixes. Avoiding functions that may throw in places where exceptions shouldn't be thrown
This commit is contained in:
parent
fd64702f31
commit
41d5abf0d8
|
@ -153,7 +153,8 @@ struct bandwidth_manager
|
||||||
m_queue.clear();
|
m_queue.clear();
|
||||||
m_history.clear();
|
m_history.clear();
|
||||||
m_current_quota = 0;
|
m_current_quota = 0;
|
||||||
m_history_timer.cancel();
|
error_code ec;
|
||||||
|
m_history_timer.cancel(ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -54,7 +54,8 @@ public:
|
||||||
: m_context(io_service, asio::ssl::context::sslv23_client)
|
: m_context(io_service, asio::ssl::context::sslv23_client)
|
||||||
, m_sock(io_service, m_context)
|
, m_sock(io_service, m_context)
|
||||||
{
|
{
|
||||||
m_context.set_verify_mode(asio::ssl::context::verify_none);
|
error_code ec;
|
||||||
|
m_context.set_verify_mode(asio::ssl::context::verify_none, ec);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef Stream next_layer_type;
|
typedef Stream next_layer_type;
|
||||||
|
|
|
@ -206,7 +206,8 @@ void http_connection::on_connect_timeout()
|
||||||
|
|
||||||
if (!m_endpoints.empty())
|
if (!m_endpoints.empty())
|
||||||
{
|
{
|
||||||
m_sock.close();
|
error_code ec;
|
||||||
|
m_sock.close(ec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -227,8 +228,8 @@ void http_connection::on_timeout(boost::weak_ptr<http_connection> p
|
||||||
{
|
{
|
||||||
if (c->m_connection_ticket > -1 && !c->m_endpoints.empty())
|
if (c->m_connection_ticket > -1 && !c->m_endpoints.empty())
|
||||||
{
|
{
|
||||||
c->m_sock.close();
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
c->m_sock.close(ec);
|
||||||
c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec);
|
c->m_timer.expires_at(c->m_last_receive + c->m_timeout, ec);
|
||||||
c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1));
|
c->m_timer.async_wait(bind(&http_connection::on_timeout, p, _1));
|
||||||
}
|
}
|
||||||
|
@ -322,7 +323,8 @@ void http_connection::on_connect(error_code const& e)
|
||||||
else if (!m_endpoints.empty() && !m_abort)
|
else if (!m_endpoints.empty() && !m_abort)
|
||||||
{
|
{
|
||||||
// The connection failed. Try the next endpoint in the list.
|
// The connection failed. Try the next endpoint in the list.
|
||||||
m_sock.close();
|
error_code ec;
|
||||||
|
m_sock.close(ec);
|
||||||
queue_connect();
|
queue_connect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -354,7 +356,8 @@ void http_connection::callback(error_code const& e, char const* data, int size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_called = true;
|
m_called = true;
|
||||||
m_timer.cancel();
|
error_code ec;
|
||||||
|
m_timer.cancel(ec);
|
||||||
if (m_handler) m_handler(e, m_parser, data, size, *this);
|
if (m_handler) m_handler(e, m_parser, data, size, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,8 +157,9 @@ namespace libtorrent
|
||||||
|
|
||||||
if (m_settings.announce_ip != address())
|
if (m_settings.announce_ip != address())
|
||||||
{
|
{
|
||||||
url += "&ip=";
|
error_code ec;
|
||||||
url += m_settings.announce_ip.to_string();
|
std::string ip = m_settings.announce_ip.to_string(ec);
|
||||||
|
if (!ec) url += "&ip=" + ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_ENCRYPTION
|
#ifndef TORRENT_DISABLE_ENCRYPTION
|
||||||
|
@ -382,7 +383,9 @@ namespace libtorrent
|
||||||
|
|
||||||
peer_entry p;
|
peer_entry p;
|
||||||
p.pid.clear();
|
p.pid.clear();
|
||||||
p.ip = detail::read_v4_address(i).to_string();
|
error_code ec;
|
||||||
|
p.ip = detail::read_v4_address(i).to_string(ec);
|
||||||
|
if (ec) continue;
|
||||||
p.port = detail::read_uint16(i);
|
p.port = detail::read_uint16(i);
|
||||||
peer_list.push_back(p);
|
peer_list.push_back(p);
|
||||||
}
|
}
|
||||||
|
@ -414,7 +417,9 @@ namespace libtorrent
|
||||||
|
|
||||||
peer_entry p;
|
peer_entry p;
|
||||||
p.pid.clear();
|
p.pid.clear();
|
||||||
p.ip = detail::read_v6_address(i).to_string();
|
error_code ec;
|
||||||
|
p.ip = detail::read_v6_address(i).to_string(ec);
|
||||||
|
if (ec) continue;
|
||||||
p.port = detail::read_uint16(i);
|
p.port = detail::read_uint16(i);
|
||||||
peer_list.push_back(p);
|
peer_list.push_back(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,10 +88,12 @@ namespace
|
||||||
void read_endpoint_list(libtorrent::entry const* n, std::vector<EndpointType>& epl)
|
void read_endpoint_list(libtorrent::entry const* n, std::vector<EndpointType>& epl)
|
||||||
{
|
{
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
if (n->type() != entry::list_t) return;
|
||||||
entry::list_type const& contacts = n->list();
|
entry::list_type const& contacts = n->list();
|
||||||
for (entry::list_type::const_iterator i = contacts.begin()
|
for (entry::list_type::const_iterator i = contacts.begin()
|
||||||
, end(contacts.end()); i != end; ++i)
|
, end(contacts.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
|
if (i->type() != entry::string_t) return;
|
||||||
std::string const& p = i->string();
|
std::string const& p = i->string();
|
||||||
if (p.size() < 6) continue;
|
if (p.size() < 6) continue;
|
||||||
std::string::const_iterator in = p.begin();
|
std::string::const_iterator in = p.begin();
|
||||||
|
@ -192,14 +194,15 @@ namespace libtorrent { namespace dht
|
||||||
m_dht.set_node_id(boost::lexical_cast<node_id>(nid->string()));
|
m_dht.set_node_id(boost::lexical_cast<node_id>(nid->string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_timer.expires_from_now(seconds(1));
|
error_code ec;
|
||||||
|
m_timer.expires_from_now(seconds(1), ec);
|
||||||
m_timer.async_wait(bind(&dht_tracker::tick, self(), _1));
|
m_timer.async_wait(bind(&dht_tracker::tick, self(), _1));
|
||||||
|
|
||||||
m_connection_timer.expires_from_now(seconds(10));
|
m_connection_timer.expires_from_now(seconds(10), ec);
|
||||||
m_connection_timer.async_wait(
|
m_connection_timer.async_wait(
|
||||||
bind(&dht_tracker::connection_timeout, self(), _1));
|
bind(&dht_tracker::connection_timeout, self(), _1));
|
||||||
|
|
||||||
m_refresh_timer.expires_from_now(seconds(5));
|
m_refresh_timer.expires_from_now(seconds(5), ec);
|
||||||
m_refresh_timer.async_wait(bind(&dht_tracker::refresh_timeout, self(), _1));
|
m_refresh_timer.async_wait(bind(&dht_tracker::refresh_timeout, self(), _1));
|
||||||
|
|
||||||
m_dht.bootstrap(initial_nodes, bind(&dht_tracker::on_bootstrap, self()));
|
m_dht.bootstrap(initial_nodes, bind(&dht_tracker::on_bootstrap, self()));
|
||||||
|
@ -209,9 +212,10 @@ namespace libtorrent { namespace dht
|
||||||
{
|
{
|
||||||
mutex_t::scoped_lock l(m_mutex);
|
mutex_t::scoped_lock l(m_mutex);
|
||||||
m_abort = true;
|
m_abort = true;
|
||||||
m_timer.cancel();
|
error_code ec;
|
||||||
m_connection_timer.cancel();
|
m_timer.cancel(ec);
|
||||||
m_refresh_timer.cancel();
|
m_connection_timer.cancel(ec);
|
||||||
|
m_refresh_timer.cancel(ec);
|
||||||
m_host_resolver.cancel();
|
m_host_resolver.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -789,7 +793,6 @@ namespace libtorrent { namespace dht
|
||||||
void write_nodes_entry(entry& r, libtorrent::dht::msg const& m)
|
void write_nodes_entry(entry& r, libtorrent::dht::msg const& m)
|
||||||
{
|
{
|
||||||
bool ipv6_nodes = false;
|
bool ipv6_nodes = false;
|
||||||
r["nodes"] = entry(entry::string_t);
|
|
||||||
entry& n = r["nodes"];
|
entry& n = r["nodes"];
|
||||||
std::back_insert_iterator<std::string> out(n.string());
|
std::back_insert_iterator<std::string> out(n.string());
|
||||||
for (msg::nodes_t::const_iterator i = m.nodes.begin()
|
for (msg::nodes_t::const_iterator i = m.nodes.begin()
|
||||||
|
@ -806,7 +809,6 @@ namespace libtorrent { namespace dht
|
||||||
|
|
||||||
if (ipv6_nodes)
|
if (ipv6_nodes)
|
||||||
{
|
{
|
||||||
r["nodes2"] = entry(entry::list_t);
|
|
||||||
entry& p = r["nodes2"];
|
entry& p = r["nodes2"];
|
||||||
std::string endpoint;
|
std::string endpoint;
|
||||||
for (msg::nodes_t::const_iterator i = m.nodes.begin()
|
for (msg::nodes_t::const_iterator i = m.nodes.begin()
|
||||||
|
|
|
@ -126,7 +126,9 @@ bool node_impl::verify_token(msg const& m)
|
||||||
}
|
}
|
||||||
|
|
||||||
hasher h1;
|
hasher h1;
|
||||||
std::string address = m.addr.address().to_string();
|
error_code ec;
|
||||||
|
std::string address = m.addr.address().to_string(ec);
|
||||||
|
if (ec) return false;
|
||||||
h1.update(&address[0], address.length());
|
h1.update(&address[0], address.length());
|
||||||
h1.update((char*)&m_secret[0], sizeof(m_secret[0]));
|
h1.update((char*)&m_secret[0], sizeof(m_secret[0]));
|
||||||
h1.update((char*)&m.info_hash[0], sha1_hash::size);
|
h1.update((char*)&m.info_hash[0], sha1_hash::size);
|
||||||
|
@ -150,7 +152,9 @@ entry node_impl::generate_token(msg const& m)
|
||||||
std::string token;
|
std::string token;
|
||||||
token.resize(4);
|
token.resize(4);
|
||||||
hasher h;
|
hasher h;
|
||||||
std::string address = m.addr.address().to_string();
|
error_code ec;
|
||||||
|
std::string address = m.addr.address().to_string(ec);
|
||||||
|
TORRENT_ASSERT(!ec);
|
||||||
h.update(&address[0], address.length());
|
h.update(&address[0], address.length());
|
||||||
h.update((char*)&m_secret[0], sizeof(m_secret[0]));
|
h.update((char*)&m_secret[0], sizeof(m_secret[0]));
|
||||||
h.update((char*)&m.info_hash[0], sha1_hash::size);
|
h.update((char*)&m.info_hash[0], sha1_hash::size);
|
||||||
|
|
|
@ -211,8 +211,9 @@ namespace
|
||||||
virtual boost::shared_ptr<peer_plugin> new_connection(
|
virtual boost::shared_ptr<peer_plugin> new_connection(
|
||||||
peer_connection* pc)
|
peer_connection* pc)
|
||||||
{
|
{
|
||||||
|
error_code ec;
|
||||||
return boost::shared_ptr<peer_plugin>(new logger_peer_plugin(
|
return boost::shared_ptr<peer_plugin>(new logger_peer_plugin(
|
||||||
pc->remote().address().to_string() + "_"
|
pc->remote().address().to_string(ec) + "_"
|
||||||
+ boost::lexical_cast<std::string>(pc->remote().port()) + ".log"));
|
+ boost::lexical_cast<std::string>(pc->remote().port()) + ".log"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -909,8 +909,9 @@ namespace libtorrent
|
||||||
if (req.left == -1) req.left = 16*1024;
|
if (req.left == -1) req.left = 16*1024;
|
||||||
req.event = e;
|
req.event = e;
|
||||||
tcp::endpoint ep = m_ses.get_ipv6_interface();
|
tcp::endpoint ep = m_ses.get_ipv6_interface();
|
||||||
|
error_code ec;
|
||||||
if (ep != tcp::endpoint())
|
if (ep != tcp::endpoint())
|
||||||
req.ipv6 = ep.address().to_string();
|
req.ipv6 = ep.address().to_string(ec);
|
||||||
|
|
||||||
req.url = m_trackers[m_currently_trying_tracker].url;
|
req.url = m_trackers[m_currently_trying_tracker].url;
|
||||||
// if we are aborting. we don't want any new peers
|
// if we are aborting. we don't want any new peers
|
||||||
|
@ -2402,9 +2403,15 @@ namespace libtorrent
|
||||||
|| p->in_handshake()
|
|| p->in_handshake()
|
||||||
|| p->remote().address().is_v6()) return;
|
|| p->remote().address().is_v6()) return;
|
||||||
|
|
||||||
m_resolving_country = true;
|
|
||||||
asio::ip::address_v4 reversed(swap_bytes(p->remote().address().to_v4().to_ulong()));
|
asio::ip::address_v4 reversed(swap_bytes(p->remote().address().to_v4().to_ulong()));
|
||||||
tcp::resolver::query q(reversed.to_string() + ".zz.countries.nerd.dk", "0");
|
error_code ec;
|
||||||
|
tcp::resolver::query q(reversed.to_string(ec) + ".zz.countries.nerd.dk", "0");
|
||||||
|
if (ec)
|
||||||
|
{
|
||||||
|
p->set_country("!!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_resolving_country = true;
|
||||||
m_host_resolver.async_resolve(q,
|
m_host_resolver.async_resolve(q,
|
||||||
bind(&torrent::on_country_lookup, shared_from_this(), _1, _2, p));
|
bind(&torrent::on_country_lookup, shared_from_this(), _1, _2, p));
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,7 +515,7 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
#ifdef BOOST_NO_EXCEPTIONS
|
#ifdef BOOST_NO_EXCEPTIONS
|
||||||
const static torrent_info empty;
|
const static torrent_info empty(sha1_hash(0));
|
||||||
#endif
|
#endif
|
||||||
boost::shared_ptr<torrent> t = m_torrent.lock();
|
boost::shared_ptr<torrent> t = m_torrent.lock();
|
||||||
if (!t)
|
if (!t)
|
||||||
|
@ -546,7 +546,7 @@ namespace libtorrent
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
entry ret(entry::dictionary_t);
|
entry ret(entry::dictionary_t);
|
||||||
TORRENT_FORWARD(write_resume_data(ret));
|
TORRENT_FORWARD_RETURN2(write_resume_data(ret), ret);
|
||||||
t->filesystem().write_resume_data(ret);
|
t->filesystem().write_resume_data(ret);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue