cleaned up some exception handling and introduced macros like BOOST_TRY/BOOST_CATCH to make the optional exception handling nicer

This commit is contained in:
Arvid Norberg
2011-02-25 17:00:36 +00:00
parent 5f5ba94462
commit 56937edf56
13 changed files with 171 additions and 266 deletions

View File

@@ -273,20 +273,16 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
if (e)
{
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
TORRENT_TRY {
#if TORRENT_USE_IPV6
if (s == &m_ipv6_sock)
m_callback(e, m_v6_ep, 0, 0);
else
if (s == &m_ipv6_sock)
m_callback(e, m_v6_ep, 0, 0);
else
#endif
m_callback(e, m_v4_ep, 0, 0);
m_callback(e, m_v4_ep, 0, 0);
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
} TORRENT_CATCH (std::exception&) {}
// don't stop listening on recoverable errors
if (e != asio::error::host_unreachable
@@ -340,24 +336,20 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#if TORRENT_USE_IPV6
if (s == &m_ipv6_sock)
{
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
TORRENT_TRY {
if (m_tunnel_packets)
{
// if the source IP doesn't match the proxy's, ignore the packet
if (m_v6_ep == m_proxy_addr)
unwrap(e, m_v6_buf, bytes_transferred);
}
else
{
m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);
}
if (m_tunnel_packets)
{
// if the source IP doesn't match the proxy's, ignore the packet
if (m_v6_ep == m_proxy_addr)
unwrap(e, m_v6_buf, bytes_transferred);
}
else
{
m_callback(e, m_v6_ep, m_v6_buf, bytes_transferred);
}
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
} TORRENT_CATCH (std::exception&) {}
if (m_abort) return;
@@ -378,24 +370,20 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_
#endif // TORRENT_USE_IPV6
{
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
TORRENT_TRY {
if (m_tunnel_packets)
{
// if the source IP doesn't match the proxy's, ignore the packet
if (m_v4_ep == m_proxy_addr)
unwrap(e, m_v4_buf, bytes_transferred);
}
else
{
m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);
}
if (m_tunnel_packets)
{
// if the source IP doesn't match the proxy's, ignore the packet
if (m_v4_ep == m_proxy_addr)
unwrap(e, m_v4_buf, bytes_transferred);
}
else
{
m_callback(e, m_v4_ep, m_v4_buf, bytes_transferred);
}
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
} TORRENT_CATCH (std::exception&) {}
if (m_abort) return;
@@ -732,13 +720,9 @@ void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i)
if (e)
{
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
TORRENT_TRY {
if (m_callback) m_callback(e, udp::endpoint(), 0, 0);
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
} TORRENT_CATCH (std::exception&) {}
return;
}
@@ -792,13 +776,9 @@ void udp_socket::on_connected(error_code const& e)
m_connection_ticket = -1;
if (e)
{
#ifndef BOOST_NO_EXCEPTIONS
try {
#endif
TORRENT_TRY {
if (m_callback) m_callback(e, udp::endpoint(), 0, 0);
#ifndef BOOST_NO_EXCEPTIONS
} catch(std::exception&) {}
#endif
} TORRENT_CATCH (std::exception&) {}
return;
}