From 9ed60479ce9a3a35bfc9f62f42d989a0320fa549 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 7 Oct 2012 23:34:44 +0000 Subject: [PATCH] merged udp socket fix from RC_0_16 --- ChangeLog | 1 + include/libtorrent/aux_/session_impl.hpp | 2 +- src/session_impl.cpp | 13 ++++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 144db9c5a..26f7823c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * try harder to bind the udp socket (uTP, DHT, UDP-trackers, LSD) to the same port as TCP * relax file timestamp requirements for accepting resume data * fix performance issue in web seed downloader (coalescing of blocks sometimes wouldn't work) * web seed fixes (better support for torrents without trailing / in web seeds) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index aeebdfd10..f3fd8b89e 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -769,7 +769,7 @@ namespace libtorrent boost::shared_ptr m_i2p_listen_socket; #endif - void setup_listener(listen_socket_t* s, tcp::endpoint ep, int retries + void setup_listener(listen_socket_t* s, tcp::endpoint ep, int& retries , bool v6_only, int flags, error_code& ec); // the proxy used for bittorrent diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 586039673..88a7df04a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2101,7 +2101,7 @@ namespace aux { } void session_impl::setup_listener(listen_socket_t* s, tcp::endpoint ep - , int retries, bool v6_only, int flags, error_code& ec) + , int& retries, bool v6_only, int flags, error_code& ec) { s->sock.reset(new socket_acceptor(m_io_service)); s->sock->open(ep.protocol(), ec); @@ -2201,6 +2201,8 @@ namespace aux { { TORRENT_ASSERT(is_network_thread()); +retry: + // close the open listen sockets m_listen_sockets.clear(); m_incoming_connection = false; @@ -2330,14 +2332,19 @@ namespace aux { m_udp_socket.bind(udp::endpoint(m_listen_interface.address(), m_listen_interface.port()), ec); if (ec) { - if (m_alerts.should_post()) - m_alerts.post_alert(listen_failed_alert(m_listen_interface, ec)); #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING char msg[200]; snprintf(msg, sizeof(msg), "cannot bind to UDP interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); (*m_logger) << msg << "\n"; #endif + if (m_listen_port_retries > 0) + { + m_listen_interface.port(m_listen_interface.port() + 1); + goto retry; + } + if (m_alerts.should_post()) + m_alerts.post_alert(listen_failed_alert(m_listen_interface, ec)); } else {