diff --git a/simulation/test_tracker.cpp b/simulation/test_tracker.cpp index 4fbbf3f31..fc48c9b72 100644 --- a/simulation/test_tracker.cpp +++ b/simulation/test_tracker.cpp @@ -756,7 +756,7 @@ TORRENT_TEST(tracker_ipv6_argument) TEST_CHECK(pos != std::string::npos || stop_event); got_ipv6 |= pos != std::string::npos; // make sure the IPv6 argument is url encoded - TEST_CHECK(req.substr(pos + 6, req.find_first_of(pos + 6, '&')) + TEST_CHECK(req.substr(pos + 6, req.find_first_of('&', pos + 6)) == "ffff%3a%3a1337"); return sim::send_response(200, "OK", 11) + "d5:peers0:e"; } diff --git a/src/broadcast_socket.cpp b/src/broadcast_socket.cpp index 1fb5e4e8f..99caf53e1 100644 --- a/src/broadcast_socket.cpp +++ b/src/broadcast_socket.cpp @@ -146,6 +146,8 @@ namespace libtorrent tcp::socket test(ios); error_code ec; test.open(tcp::v6(), ec); + if (ec) return false; + test.bind(tcp::endpoint(address_v6::from_string("::1"), 0), ec); return !bool(ec); #endif } diff --git a/test/test_tracker.cpp b/test/test_tracker.cpp index 76acbacad..63cd13bb6 100644 --- a/test/test_tracker.cpp +++ b/test/test_tracker.cpp @@ -403,6 +403,8 @@ void test_udp_tracker(std::string const& iface, address tracker, tcp::endpoint c // we should have announced the stopped event now TEST_EQUAL(num_udp_announces(), prev_udp_announces + 2); + + stop_udp_tracker(); } TORRENT_TEST(udp_tracker_v4) @@ -413,7 +415,10 @@ TORRENT_TEST(udp_tracker_v4) #if TORRENT_USE_IPV6 TORRENT_TEST(udp_tracker_v6) { - test_udp_tracker("[::1]", address_v6::any(), ep("::1.3.3.7", 1337)); + if (supports_ipv6()) + { + test_udp_tracker("[::1]", address_v6::any(), ep("::1.3.3.7", 1337)); + } } #endif @@ -470,10 +475,7 @@ TORRENT_TEST(http_peers) expected_peers.insert(ep("65.65.65.65", 16962)); expected_peers.insert(ep("67.67.67.67", 17476)); #if TORRENT_USE_IPV6 - if (supports_ipv6()) - { - expected_peers.insert(ep("4545:4545:4545:4545:4545:4545:4545:4545", 17990)); - } + expected_peers.insert(ep("4545:4545:4545:4545:4545:4545:4545:4545", 17990)); #endif TEST_EQUAL(peers.size(), expected_peers.size()); diff --git a/test/udp_tracker.cpp b/test/udp_tracker.cpp index 5d59abe3f..53e99a2b5 100644 --- a/test/udp_tracker.cpp +++ b/test/udp_tracker.cpp @@ -174,7 +174,7 @@ struct udp_tracker , std::bind(&udp_tracker::on_udp_receive, this, _1, _2, from, buffer, size)); } - udp_tracker(address iface) + explicit udp_tracker(address iface) : m_udp_announces(0) , m_socket(m_ios) , m_port(0) @@ -201,14 +201,15 @@ struct udp_tracker return; } - std::printf("%s: UDP tracker initialized on port %d\n", time_now_string(), m_port); + std::printf("%s: UDP tracker [%p] initialized on port %d\n" + , time_now_string(), this, m_port); m_thread = std::make_shared(&udp_tracker::thread_fun, this); } void stop() { - std::printf("%s: UDP tracker, stop\n", time_now_string()); + std::printf("%s: UDP tracker [%p], stop\n", time_now_string(), this); m_abort = true; m_socket.cancel(); m_socket.close(); @@ -216,6 +217,8 @@ struct udp_tracker ~udp_tracker() { + std::printf("%s: UDP tracker [%p], ~udp_tracker\n" + , time_now_string(), this); m_ios.post(std::bind(&udp_tracker::stop, this)); if (m_thread) m_thread->join(); } @@ -224,13 +227,6 @@ struct udp_tracker int num_hits() const { return m_udp_announces; } - static void incoming_packet(error_code const& ec, size_t bytes_transferred, size_t *ret, error_code* error, bool* done) - { - *ret = bytes_transferred; - *error = ec; - *done = true; - } - void thread_fun() { char buffer[2000]; @@ -249,7 +245,7 @@ struct udp_tracker return; } - std::printf("UDP exiting UDP tracker thread\n"); + std::printf("UDP exiting UDP tracker [%p] thread\n", this); } }; @@ -257,6 +253,7 @@ std::shared_ptr g_udp_tracker; int start_udp_tracker(address iface) { + TORRENT_ASSERT(!g_udp_tracker); g_udp_tracker.reset(new udp_tracker(iface)); return g_udp_tracker->port(); }