From fb85e5e60f60e9c371723f4ee48f6beb96698f8c Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 13 Mar 2016 16:18:44 -0400 Subject: [PATCH 1/2] improve message from listen_failed_alert. Post listen_failed_alert for every failure, including the ones that are re-tried --- src/alert.cpp | 3 ++- src/session_impl.cpp | 24 ++++++++++++------------ test/setup_transfer.cpp | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/alert.cpp b/src/alert.cpp index 79a965681..076beb0e2 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -861,8 +861,9 @@ namespace libtorrent { "accept" }; char ret[300]; - snprintf(ret, sizeof(ret), "listening on %s failed: [%s] [%s] %s" + snprintf(ret, sizeof(ret), "listening on %s : %s failed: [%s] [%s] %s" , listen_interface() + , print_endpoint(endpoint).c_str() , op_str[operation] , sock_type_str[sock_type] , convert_from_native(error.message()).c_str()); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index b38567f83..4b9f58b03 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2048,18 +2048,18 @@ retry: session_log("cannot bind TCP listen socket to interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); #endif - if (listen_port_retries > 0) - { - m_listen_interface.port(m_listen_interface.port() + 1); - --listen_port_retries; - goto retry; - } if (m_alerts.should_post()) m_alerts.emplace_alert( m_listen_interface.address().to_string() , m_listen_interface.port() , listen_failed_alert::bind , ec, listen_failed_alert::tcp); + if (listen_port_retries > 0) + { + m_listen_interface.port(m_listen_interface.port() + 1); + --listen_port_retries; + goto retry; + } return; } @@ -2119,12 +2119,6 @@ retry: session_log("cannot bind to UDP interface \"%s\": %s" , print_endpoint(m_listen_interface).c_str(), ec.message().c_str()); #endif - if (listen_port_retries > 0) - { - m_listen_interface.port(m_listen_interface.port() + 1); - --listen_port_retries; - goto retry; - } if (m_alerts.should_post()) { error_code err; @@ -2133,6 +2127,12 @@ retry: , listen_failed_alert::bind , ec, listen_failed_alert::udp); } + if (listen_port_retries > 0) + { + m_listen_interface.port(m_listen_interface.port() + 1); + --listen_port_retries; + goto retry; + } return; } else diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index e026b9def..eff42419a 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -363,9 +363,9 @@ void wait_for_downloading(lt::session& ses, char const* name) } while (a); if (!downloading_done) { - fprintf(stderr, "did not receive a state_changed_alert indicating " + fprintf(stderr, "%s: did not receive a state_changed_alert indicating " "the torrent is downloading. waited: %d ms\n" - , int(total_milliseconds(clock_type::now() - start))); + , name, int(total_milliseconds(clock_type::now() - start))); } } From c5861bcc0434a1c83085ca04c796988031834fcd Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 14 Mar 2016 18:52:43 -0400 Subject: [PATCH 2/2] fix failure to increment port when retrying socket binding --- src/session_impl.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 4b9f58b03..ac7b98f28 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2057,6 +2057,9 @@ retry: if (listen_port_retries > 0) { m_listen_interface.port(m_listen_interface.port() + 1); + // update the actual port m_listen_interface was derived from also + if (!m_listen_interfaces.empty()) + m_listen_interfaces[0].second += 1; --listen_port_retries; goto retry; } @@ -2130,6 +2133,9 @@ retry: if (listen_port_retries > 0) { m_listen_interface.port(m_listen_interface.port() + 1); + // update the actual port m_listen_interface was derived from also + if (!m_listen_interfaces.empty()) + m_listen_interfaces[0].second += 1; --listen_port_retries; goto retry; }