From 784f8806a496b0674dbdc9f131ac643061fd29eb Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 18 Jan 2016 23:13:50 -0500 Subject: [PATCH 1/7] fix asio debugging feature --- src/session.cpp | 14 ++++++++++++++ src/session_impl.cpp | 14 -------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/session.cpp b/src/session.cpp index adacc0eb5..9d3913fda 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -395,6 +395,20 @@ namespace libtorrent TORRENT_ASSERT(m_impl); TORRENT_ASYNC_CALL(abort); +#if defined TORRENT_ASIO_DEBUGGING + int counter = 0; + while (log_async()) + { + sleep(1000); + ++counter; + printf("\x1b[2J\x1b[0;0H\x1b[33m==== Waiting to shut down: %d ==== \x1b[0m\n\n" + , counter); + } + async_dec_threads(); + + fprintf(stderr, "\n\nEXPECTS NO MORE ASYNC OPS\n\n\n"); +#endif + if (m_thread && m_thread.unique()) m_thread->join(); } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 977582b6e..6f617b86a 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -5832,20 +5832,6 @@ retry: // this is not allowed to be the network thread! // TORRENT_ASSERT(is_not_thread()); -#if defined TORRENT_ASIO_DEBUGGING - int counter = 0; - while (log_async()) - { - sleep(1000); - ++counter; - printf("\x1b[2J\x1b[0;0H\x1b[33m==== Waiting to shut down: %d ==== \x1b[0m\n\n" - , counter); - } - async_dec_threads(); - - fprintf(stderr, "\n\nEXPECTS NO MORE ASYNC OPS\n\n\n"); -#endif - m_udp_socket.unsubscribe(this); m_udp_socket.unsubscribe(&m_utp_socket_manager); m_udp_socket.unsubscribe(&m_tracker_manager); From 2fa84b3aa56dd5b5b4d8aacc481effcad5743294 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 19 Jan 2016 18:47:21 -0500 Subject: [PATCH 2/7] fix incorrect use of WaitForMultipleObjects --- src/file.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 40aec5939..fc30e8d10 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -156,6 +156,21 @@ namespace // wrap the windows function in something that looks // like preadv() and pwritev() + // windows only lets us wait for 64 handles at a time, so this function makes + // sure we wait for all of them, partially in sequence + int wait_for_multiple_handles(int num_handles, HANDLE* h) + { + int batch_size = (std::min)(num_bufs, MAXIMUM_WAIT_OBJECTS); + while (WaitForMultipleObjects(batch_size, h, TRUE, INFINITE) != WAIT_FAILED) + { + h += batch_size; + num_handles -= batch_size; + batch_size = (std::min)(num_bufs, MAXIMUM_WAIT_OBJECTS); + if (batch_size <= 0) return WAIT_OBJECT_0; + } + return WAIT_FAILED; + } + int preadv(HANDLE fd, libtorrent::file::iovec_t const* bufs, int num_bufs, boost::int64_t file_offset) { OVERLAPPED* ol = TORRENT_ALLOCA(OVERLAPPED, num_bufs); @@ -194,7 +209,7 @@ namespace } } - if (WaitForMultipleObjects(num_bufs, h, TRUE, INFINITE) == WAIT_FAILED) + if (wait_for_multiple_objects(num_bufs, h) == WAIT_FAILED) { ret = -1; goto done; @@ -264,7 +279,7 @@ done: } } - if (WaitForMultipleObjects(num_bufs, h, TRUE, INFINITE) == WAIT_FAILED) + if (wait_for_multiple_objects(num_bufs, h) == WAIT_FAILED) { ret = -1; goto done; From cbc5d99de0439660a8481ae079c0eaaad168b36e Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 19 Jan 2016 20:54:34 -0500 Subject: [PATCH 3/7] update appveyor and .travis scripts --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e9664dc59..c858d5ce6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ git: branches: only: - master + - RC_1_1 - RC_1_0 # container-based builds diff --git a/appveyor.yml b/appveyor.yml index 1b533a0f0..a080522b2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ version: 1.0.{build} branches: only: - master + - RC_1_1 os: Visual Studio 2015 clone_depth: 1 environment: From fbb246094bff0bdc441616b3ff4fc2907107ec61 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 19 Jan 2016 21:21:00 -0500 Subject: [PATCH 4/7] fix windows build --- src/file.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index fc30e8d10..33b7f5d7e 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -158,14 +158,14 @@ namespace // windows only lets us wait for 64 handles at a time, so this function makes // sure we wait for all of them, partially in sequence - int wait_for_multiple_handles(int num_handles, HANDLE* h) + int wait_for_multiple_objects(int num_handles, HANDLE* h) { - int batch_size = (std::min)(num_bufs, MAXIMUM_WAIT_OBJECTS); + int batch_size = (std::min)(num_handles, MAXIMUM_WAIT_OBJECTS); while (WaitForMultipleObjects(batch_size, h, TRUE, INFINITE) != WAIT_FAILED) { h += batch_size; num_handles -= batch_size; - batch_size = (std::min)(num_bufs, MAXIMUM_WAIT_OBJECTS); + batch_size = (std::min)(num_handles, MAXIMUM_WAIT_OBJECTS); if (batch_size <= 0) return WAIT_OBJECT_0; } return WAIT_FAILED; From 0cb35d714c9227140acc26b9593904f7babe2d67 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 20 Jan 2016 19:38:18 -0500 Subject: [PATCH 5/7] fix test in test_storage --- test/test_storage.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_storage.cpp b/test/test_storage.cpp index 7736dccb8..06e3699d7 100644 --- a/test/test_storage.cpp +++ b/test/test_storage.cpp @@ -779,7 +779,6 @@ TORRENT_TEST(rename_file_fastresume) { if (print_alerts(ses, "ses", true, true, true, &got_file_rename_alert)) renamed = true; torrent_status s = h.status(); - if (s.state == torrent_status::downloading) break; if (s.state == torrent_status::seeding && renamed) break; test_sleep(100); } From 218d33c545ed5e4e6e7c88821e805030e6ca0b09 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 20 Jan 2016 20:48:23 -0500 Subject: [PATCH 6/7] Documentation typos and minor cleanup --- include/libtorrent/settings_pack.hpp | 2 +- include/libtorrent/sha1_hash.hpp | 2 +- src/block_cache.cpp | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 9531ecb9c..e10c779d2 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -451,7 +451,7 @@ namespace libtorrent // ``no_recheck_incomplete_resume`` determines if the storage should // check the whole files when resume data is incomplete or missing or // whether it should simply assume we don't have any of the data. By - // default, this is determined by the existance of any of the files. + // default, this is determined by the existence of any of the files. // By setting this setting to true, the files won't be checked, but // will go straight to download mode. no_recheck_incomplete_resume, diff --git a/include/libtorrent/sha1_hash.hpp b/include/libtorrent/sha1_hash.hpp index b1d53b7a5..57e7d4140 100644 --- a/include/libtorrent/sha1_hash.hpp +++ b/include/libtorrent/sha1_hash.hpp @@ -73,7 +73,7 @@ namespace libtorrent // the number of bytes of the number static const int size = number_size * sizeof(boost::uint32_t); - // constructs an all-sero sha1-hash + // constructs an all-zero sha1-hash sha1_hash() { clear(); } // returns an all-F sha1-hash. i.e. the maximum value diff --git a/src/block_cache.cpp b/src/block_cache.cpp index d68964a10..b51f9a923 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -70,7 +70,7 @@ const vm_purgable_t vm_purgable_nonvolatile = VM_PURGABLE_NONVOLATILE; See slides: http://www-vlsi.stanford.edu/smart_memories/protected/meetings/spring2004/arc-fast.pdf This cache has a few modifications to make it fit the bittorrent use - case better. It has a few more lists and it deferres the eviction + case better. It has a few more lists and it defers the eviction of pieces. read_lru1 @@ -437,7 +437,7 @@ void block_cache::cache_hit(cached_piece_entry* p, void* requester, bool volatil TORRENT_ASSERT(p); TORRENT_ASSERT(p->in_use); - // move the piece into this queue. Whenever we have a cahe + // move the piece into this queue. Whenever we have a cache // hit, we move the piece into the lru2 queue (i.e. the most // frequently used piece). However, we only do that if the // requester is different than the last one. This is to @@ -1837,8 +1837,6 @@ bool block_cache::maybe_free_piece(cached_piece_entry* pe) || !pe->jobs.empty()) return false; - boost::shared_ptr s = pe->storage; - DLOG(stderr, "[%p] block_cache maybe_free_piece " "piece: %d refcount: %d marked_for_deletion: %d\n" , static_cast(this) From 5c94b286b0c7008553b79029a5410149255752a7 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Mon, 18 Jan 2016 17:59:30 -0500 Subject: [PATCH 7/7] Removed file::m_path windows specific field Removed default_storage::sparse_end Typos --- include/libtorrent/file.hpp | 6 ------ include/libtorrent/storage.hpp | 2 -- include/libtorrent/torrent.hpp | 4 ++-- src/file.cpp | 36 ++++++++++++++-------------------- src/storage.cpp | 26 ------------------------ 5 files changed, 17 insertions(+), 57 deletions(-) diff --git a/include/libtorrent/file.hpp b/include/libtorrent/file.hpp index c147ff599..93b3a294b 100644 --- a/include/libtorrent/file.hpp +++ b/include/libtorrent/file.hpp @@ -345,12 +345,6 @@ namespace libtorrent boost::uint32_t m_file_id; #endif -#if defined TORRENT_WINDOWS && TORRENT_USE_WSTRING - std::wstring m_path; -#elif defined TORRENT_WINDOWS - std::string m_path; -#endif // TORRENT_WINDOWS - int m_open_mode; #if defined TORRENT_WINDOWS static bool has_manage_volume_privs; diff --git a/include/libtorrent/storage.hpp b/include/libtorrent/storage.hpp index a84907a3c..ccd8e94aa 100644 --- a/include/libtorrent/storage.hpp +++ b/include/libtorrent/storage.hpp @@ -452,8 +452,6 @@ namespace libtorrent private: - int sparse_end(int start) const; - void delete_one_file(std::string const& p, error_code& ec); void need_partfile(); diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 68c994bc9..ed766e86c 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -192,7 +192,7 @@ namespace libtorrent // the case there is no piece picker, see m_have_all. boost::scoped_ptr m_picker; - // TOOD: make this a raw pointer. perhaps keep the shared_ptr + // TODO: make this a raw pointer. perhaps keep the shared_ptr // around further down the object to maintain an owner boost::shared_ptr m_torrent_file; @@ -204,7 +204,7 @@ namespace libtorrent // use sorted_insert() and sorted_find() on it. The GNU STL // implementation on Darwin uses significantly less memory to // represent a vector than a set, and this set is typically - // relaitvely small, and it's cheap to copy pointers. + // relatively small, and it's cheap to copy pointers. std::vector m_connections; // the scrape data from the tracker response, this diff --git a/src/file.cpp b/src/file.cpp index 33b7f5d7e..6cc99de01 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -1391,10 +1391,10 @@ namespace libtorrent #if TORRENT_USE_WSTRING #define CreateFile_ CreateFileW - m_path = convert_to_wstring(p); + std::wstring file_path = convert_to_wstring(p); #else #define CreateFile_ CreateFileA - m_path = convert_to_native(p); + std::string file_path = convert_to_native(p); #endif TORRENT_ASSERT((mode & rw_mask) < sizeof(mode_array)/sizeof(mode_array[0])); @@ -1411,7 +1411,7 @@ namespace libtorrent | ((mode & direct_io) ? FILE_FLAG_NO_BUFFERING : 0) | ((mode & no_cache) ? FILE_FLAG_WRITE_THROUGH : 0); - handle_type handle = CreateFile_(m_path.c_str(), m.rw_mode + handle_type handle = CreateFile_(file_path.c_str(), m.rw_mode , (mode & lock_file) ? FILE_SHARE_READ : FILE_SHARE_READ | FILE_SHARE_WRITE , 0, m.create_mode, flags, 0); @@ -1635,7 +1635,6 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { } CloseHandle(native_handle()); - m_path.clear(); #else if (m_file_handle != INVALID_HANDLE_VALUE) ::close(m_file_handle); @@ -2053,26 +2052,21 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { if ((m_open_mode & sparse) == 0) { -#if TORRENT_USE_WSTRING - typedef DWORD (WINAPI *GetCompressedFileSize_t)(LPCWSTR lpFileName, LPDWORD lpFileSizeHigh); -#else - typedef DWORD (WINAPI *GetCompressedFileSize_t)(LPCSTR lpFileName, LPDWORD lpFileSizeHigh); -#endif + typedef DWORD (WINAPI *GetFileInformationByHandleEx_t)(HANDLE hFile + , FILE_INFO_BY_HANDLE_CLASS FileInformationClass + , LPVOID lpFileInformation + , DWORD dwBufferSize); - static GetCompressedFileSize_t GetCompressedFileSize_ = NULL; + static GetFileInformationByHandleEx_t GetFileInformationByHandleEx_ = NULL; static bool failed_kernel32 = false; - if ((GetCompressedFileSize_ == NULL) && !failed_kernel32) + if ((GetFileInformationByHandleEx_ == NULL) && !failed_kernel32) { HMODULE kernel32 = LoadLibraryA("kernel32.dll"); if (kernel32) { -#if TORRENT_USE_WSTRING - GetCompressedFileSize_ = (GetCompressedFileSize_t)GetProcAddress(kernel32, "GetCompressedFileSizeW"); -#else - GetCompressedFileSize_ = (GetCompressedFileSize_t)GetProcAddress(kernel32, "GetCompressedFileSizeA"); -#endif + GetFileInformationByHandleEx_ = (GetFileInformationByHandleEx_t)GetProcAddress(kernel32, "GetFileInformationByHandleEx"); } else { @@ -2081,18 +2075,18 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER { } offs.QuadPart = 0; - if (GetCompressedFileSize_) + if (GetFileInformationByHandleEx_) { // only allocate the space if the file // is not fully allocated - DWORD high_dword = 0; - offs.LowPart = GetCompressedFileSize_(m_path.c_str(), &high_dword); - offs.HighPart = high_dword; - if (offs.LowPart == INVALID_FILE_SIZE) + FILE_STANDARD_INFO inf; + if (GetFileInformationByHandleEx_(native_handle() + , FileStandardInfo, &inf, sizeof(inf)) == FALSE) { ec.assign(GetLastError(), system_category()); if (ec) return false; } + offs = inf.AllocationSize; } if (offs.QuadPart != s) diff --git a/src/storage.cpp b/src/storage.cpp index 026b1b77d..7f18bb6df 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -888,32 +888,6 @@ namespace libtorrent } } - int default_storage::sparse_end(int piece) const - { - TORRENT_ASSERT(piece >= 0); - TORRENT_ASSERT(piece < files().num_pieces()); - - boost::int64_t file_offset = boost::int64_t(piece) * files().piece_length(); - int file_index = 0; - - for (;;) - { - if (file_offset < files().file_size(file_index)) - break; - - file_offset -= files().file_size(file_index); - ++file_index; - TORRENT_ASSERT(file_index != files().num_files()); - } - - error_code ec; - file_handle handle = open_file_impl(file_index, file::read_only, ec); - if (ec) return piece; - - boost::int64_t data_start = handle->sparse_end(file_offset); - return int((data_start + files().piece_length() - 1) / files().piece_length()); - } - bool default_storage::verify_resume_data(bdecode_node const& rd , std::vector const* links , storage_error& ec)