From 192a82922233ffa0b17c346bc68e558a51ce62dc Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 9 Feb 2011 08:01:53 +0000 Subject: [PATCH] fixed udp-socket race condition when using a proxy --- ChangeLog | 1 + src/udp_socket.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 25c2f26d9..d2e584555 100644 --- a/ChangeLog +++ b/ChangeLog @@ -81,6 +81,7 @@ incoming connection * added more detailed instrumentation of the disk I/O thread + * fixed udp-socket race condition when using a proxy * end-game mode optimizations * fixed bug in udp_socket causing it to issue two simultaneous async. read operations * fixed mingw build diff --git a/src/udp_socket.cpp b/src/udp_socket.cpp index cc54906e0..944fcf19e 100644 --- a/src/udp_socket.cpp +++ b/src/udp_socket.cpp @@ -238,6 +238,7 @@ void udp_socket::on_read(udp::socket* s, error_code const& e, std::size_t bytes_ #if defined TORRENT_ASIO_DEBUGGING complete_async("udp_socket::on_read"); #endif + TORRENT_ASSERT(m_magic == 0x1337); TORRENT_ASSERT(is_single_thread()); @@ -715,11 +716,23 @@ void udp_socket::set_proxy_settings(proxy_settings const& ps) void udp_socket::on_name_lookup(error_code const& e, tcp::resolver::iterator i) { - if (e) return; + if (e == asio::error::operation_aborted) return; CHECK_MAGIC; TORRENT_ASSERT(is_single_thread()); + if (e) + { +#ifndef BOOST_NO_EXCEPTIONS + try { +#endif + if (m_callback) m_callback(e, udp::endpoint(), 0, 0); +#ifndef BOOST_NO_EXCEPTIONS + } catch(std::exception&) {} +#endif + return; + } + m_proxy_addr.address(i->endpoint().address()); m_proxy_addr.port(i->endpoint().port()); // on_connect may be called from within this thread @@ -743,6 +756,7 @@ void udp_socket::on_connect(int ticket) TORRENT_ASSERT(is_single_thread()); if (m_abort) return; + if (is_closed()) return; #if defined TORRENT_ASIO_DEBUGGING add_outstanding_async("udp_socket::on_connected"); @@ -759,12 +773,25 @@ void udp_socket::on_connected(error_code const& e) #if defined TORRENT_ASIO_DEBUGGING complete_async("udp_socket::on_connected"); #endif + + if (e == asio::error::operation_aborted) return; + CHECK_MAGIC; TORRENT_ASSERT(is_single_thread()); m_cc.done(m_connection_ticket); m_connection_ticket = -1; - if (e) return; + if (e) + { +#ifndef BOOST_NO_EXCEPTIONS + try { +#endif + if (m_callback) m_callback(e, udp::endpoint(), 0, 0); +#ifndef BOOST_NO_EXCEPTIONS + } catch(std::exception&) {} +#endif + return; + } using namespace libtorrent::detail;