From d3ba5edd6d02ab98357113e33e9c20c3afbb4647 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 24 Jun 2006 22:30:59 +0000 Subject: [PATCH] fixed a long standing (quite rare) bug, thanks to Massaroddel. Made the tests clean up their temporary files. --- src/peer_connection.cpp | 1 + src/session.cpp | 8 ++++++-- src/torrent.cpp | 1 + test/test_metadata_extension.cpp | 6 +++++- test/test_storage.cpp | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 4f268704a..1800f62b8 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -316,6 +316,7 @@ namespace libtorrent peer_connection::~peer_connection() { // INVARIANT_CHECK; + assert(m_disconnecting); #ifdef TORRENT_VERBOSE_LOGGING using namespace boost::posix_time; diff --git a/src/session.cpp b/src/session.cpp index fa8521070..54a86eca4 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -599,6 +599,8 @@ namespace libtorrent { namespace detail } catch (std::exception& e) { + c->disconnect(); + #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) (*m_logger) << "connect failed [" << c->remote() << "]: " << e.what() << "\n"; @@ -750,8 +752,10 @@ namespace libtorrent { namespace detail // has to be in the queue, waiting to be connected. connection_queue::iterator j = std::find( m_connection_queue.begin(), m_connection_queue.end(), p); - - assert(j != m_connection_queue.end()); + + // if this connection was closed while being connected + // it has been removed from the connection queue and + // not yet put into the half-open queue. if (j != m_connection_queue.end()) m_connection_queue.erase(j); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 8df4b00e4..f20ac44ae 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1073,6 +1073,7 @@ namespace libtorrent c->disconnect(); throw; } + if (c->is_disconnecting()) throw protocol_error("failed to connect"); return *c; } diff --git a/test/test_metadata_extension.cpp b/test/test_metadata_extension.cpp index 49a4414af..7cf310202 100644 --- a/test/test_metadata_extension.cpp +++ b/test/test_metadata_extension.cpp @@ -55,7 +55,8 @@ void test_transfer(bool clear_files = true, bool disconnect = false) int test_main() { using namespace libtorrent; - + using namespace boost::filesystem; + // test to disconnect one client prematurely test_transfer(true, true); @@ -65,6 +66,9 @@ int test_main() // test where both have data (to trigger the file check) test_transfer(false); + remove_all("./tmp1"); + remove_all("./tmp2"); + return 0; } diff --git a/test/test_storage.cpp b/test/test_storage.cpp index f43563039..495d7a8f3 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -99,6 +99,8 @@ int test_main() pm.read(piece, 2, 0, piece_size); TEST_CHECK(std::equal(piece, piece + piece_size, piece2)); + remove_all(initial_path() / "temp_storage"); + return 0; }