forked from premiere/premiere-libtorrent
merged RC_1_1 into master
This commit is contained in:
commit
3153521367
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -192,7 +192,7 @@ namespace libtorrent
|
|||
// the case there is no piece picker, see m_have_all.
|
||||
boost::scoped_ptr<piece_picker> 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<torrent_info> 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<peer_connection*> m_connections;
|
||||
|
||||
// the scrape data from the tracker response, this
|
||||
|
|
|
@ -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<piece_manager> s = pe->storage;
|
||||
|
||||
DLOG(stderr, "[%p] block_cache maybe_free_piece "
|
||||
"piece: %d refcount: %d marked_for_deletion: %d\n"
|
||||
, static_cast<void*>(this)
|
||||
|
|
55
src/file.cpp
55
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_objects(int num_handles, HANDLE* h)
|
||||
{
|
||||
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_handles, 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;
|
||||
|
@ -1376,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]));
|
||||
|
@ -1396,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);
|
||||
|
||||
|
@ -1620,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);
|
||||
|
@ -2038,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
|
||||
{
|
||||
|
@ -2066,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)
|
||||
|
|
|
@ -391,6 +391,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();
|
||||
}
|
||||
|
|
|
@ -5831,20 +5831,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);
|
||||
|
|
|
@ -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<std::string> const* links
|
||||
, storage_error& ec)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue