added exception handling to upnp

This commit is contained in:
Arvid Norberg 2007-05-10 18:00:10 +00:00
parent 23ae2e12c8
commit acf973fe39
1 changed files with 35 additions and 7 deletions

View File

@ -150,7 +150,7 @@ catch (std::exception& e)
m_callback(0, 0, msg.str()); m_callback(0, 0, msg.str());
}; };
void upnp::discover_device() void upnp::discover_device() try
{ {
const char msearch[] = const char msearch[] =
"M-SEARCH * HTTP/1.1\r\n" "M-SEARCH * HTTP/1.1\r\n"
@ -176,6 +176,10 @@ void upnp::discover_device()
<< " ==> Broadcasting search for rootdevice" << std::endl; << " ==> Broadcasting search for rootdevice" << std::endl;
#endif #endif
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::set_mappings(int tcp, int udp) void upnp::set_mappings(int tcp, int udp)
{ {
@ -207,7 +211,7 @@ void upnp::set_mappings(int tcp, int udp)
} }
} }
void upnp::resend_request(asio::error_code const& e) void upnp::resend_request(asio::error_code const& e) try
{ {
if (e) return; if (e) return;
if (m_retry_count < 9 if (m_retry_count < 9
@ -243,9 +247,13 @@ void upnp::resend_request(asio::error_code const& e)
} }
} }
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::on_reply(asio::error_code const& e void upnp::on_reply(asio::error_code const& e
, std::size_t bytes_transferred) , std::size_t bytes_transferred) try
{ {
using namespace libtorrent::detail; using namespace libtorrent::detail;
if (e) return; if (e) return;
@ -384,6 +392,10 @@ void upnp::on_reply(asio::error_code const& e
} }
} }
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::post(rootdevice& d, std::stringstream const& soap void upnp::post(rootdevice& d, std::stringstream const& soap
, std::string const& soap_action) , std::string const& soap_action)
@ -548,7 +560,7 @@ namespace
} }
void upnp::on_upnp_xml(asio::error_code const& e void upnp::on_upnp_xml(asio::error_code const& e
, libtorrent::http_parser const& p, rootdevice& d) , libtorrent::http_parser const& p, rootdevice& d) try
{ {
if (d.upnp_connection) if (d.upnp_connection)
{ {
@ -613,6 +625,10 @@ void upnp::on_upnp_xml(asio::error_code const& e
map_port(d, 0); map_port(d, 0);
} }
catch (std::exception&)
{
m_disabled = true;
}
namespace namespace
{ {
@ -667,7 +683,7 @@ namespace
} }
void upnp::on_upnp_map_response(asio::error_code const& e void upnp::on_upnp_map_response(asio::error_code const& e
, libtorrent::http_parser const& p, rootdevice& d, int mapping) , libtorrent::http_parser const& p, rootdevice& d, int mapping) try
{ {
if (d.upnp_connection) if (d.upnp_connection)
{ {
@ -803,9 +819,13 @@ void upnp::on_upnp_map_response(asio::error_code const& e
} }
} }
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::on_upnp_unmap_response(asio::error_code const& e void upnp::on_upnp_unmap_response(asio::error_code const& e
, libtorrent::http_parser const& p, rootdevice& d, int mapping) , libtorrent::http_parser const& p, rootdevice& d, int mapping) try
{ {
if (d.upnp_connection) if (d.upnp_connection)
{ {
@ -847,8 +867,12 @@ void upnp::on_upnp_unmap_response(asio::error_code const& e
// all the unmap operations to complete // all the unmap operations to complete
m_devices.erase(d); m_devices.erase(d);
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::on_expire(asio::error_code const& e) void upnp::on_expire(asio::error_code const& e) try
{ {
if (e) return; if (e) return;
@ -881,6 +905,10 @@ void upnp::on_expire(asio::error_code const& e)
m_refresh_timer.async_wait(m_strand.wrap(bind(&upnp::on_expire, this, _1))); m_refresh_timer.async_wait(m_strand.wrap(bind(&upnp::on_expire, this, _1)));
} }
} }
catch (std::exception&)
{
m_disabled = true;
}
void upnp::close() void upnp::close()
{ {