improve support for windows XP and earlier
This commit is contained in:
@@ -101,6 +101,73 @@ namespace libtorrent
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
void set_low_priority(boost::intrusive_ptr<file> const& f)
|
||||
{
|
||||
// file prio is only supported on vista and up
|
||||
// so load the functions dynamically
|
||||
typedef enum _FILE_INFO_BY_HANDLE_CLASS {
|
||||
FileBasicInfo,
|
||||
FileStandardInfo,
|
||||
FileNameInfo,
|
||||
FileRenameInfo,
|
||||
FileDispositionInfo,
|
||||
FileAllocationInfo,
|
||||
FileEndOfFileInfo,
|
||||
FileStreamInfo,
|
||||
FileCompressionInfo,
|
||||
FileAttributeTagInfo,
|
||||
FileIdBothDirectoryInfo,
|
||||
FileIdBothDirectoryRestartInfo,
|
||||
FileIoPriorityHintInfo,
|
||||
FileRemoteProtocolInfo,
|
||||
MaximumFileInfoByHandleClass
|
||||
} FILE_INFO_BY_HANDLE_CLASS, *PFILE_INFO_BY_HANDLE_CLASS;
|
||||
|
||||
typedef enum _PRIORITY_HINT {
|
||||
IoPriorityHintVeryLow = 0,
|
||||
IoPriorityHintLow,
|
||||
IoPriorityHintNormal,
|
||||
MaximumIoPriorityHintType
|
||||
} PRIORITY_HINT;
|
||||
|
||||
typedef struct _FILE_IO_PRIORITY_HINT_INFO {
|
||||
PRIORITY_HINT PriorityHint;
|
||||
} FILE_IO_PRIORITY_HINT_INFO, *PFILE_IO_PRIORITY_HINT_INFO;
|
||||
|
||||
typedef BOOL (WINAPI *SetFileInformationByHandle_t)(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize);
|
||||
static SetFileInformationByHandle_t SetFileInformationByHandle = NULL;
|
||||
|
||||
static bool failed_kernel_load = false;
|
||||
|
||||
if (failed_kernel_load) return;
|
||||
|
||||
if (SetFileInformationByHandle == NULL)
|
||||
{
|
||||
HMODULE kernel32 = LoadLibraryA("kernel32.dll");
|
||||
if (kernel32 == NULL)
|
||||
{
|
||||
failed_kernel_load = true;
|
||||
return;
|
||||
}
|
||||
|
||||
SetFileInformationByHandle = (SetFileInformationByHandle_t)GetProcAddress(kernel32, "SetFileInformationByHandle");
|
||||
if (SetFileInformationByHandle == NULL)
|
||||
{
|
||||
failed_kernel_load = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TORRENT_ASSERT(SetFileInformationByHandle);
|
||||
|
||||
FILE_IO_PRIORITY_HINT_INFO io_hint;
|
||||
io_hint.PriorityHint = IoPriorityHintLow;
|
||||
SetFileInformationByHandle(f->native_handle(),
|
||||
FileIoPriorityHintInfo, &io_hint, sizeof(io_hint));
|
||||
}
|
||||
#endif // TORRENT_WINDOWS
|
||||
|
||||
boost::intrusive_ptr<file> file_pool::open_file(void* st, std::string const& p
|
||||
, file_storage::iterator fe, file_storage const& fs, int m, error_code& ec)
|
||||
{
|
||||
@@ -154,17 +221,8 @@ namespace libtorrent
|
||||
return boost::intrusive_ptr<file>();
|
||||
}
|
||||
#ifdef TORRENT_WINDOWS
|
||||
// file prio is supported on vista and up
|
||||
#if _WIN32_WINNT >= 0x0600
|
||||
if (m_low_prio_io)
|
||||
{
|
||||
// TODO: load this function dynamically from Kernel32.dll
|
||||
FILE_IO_PRIORITY_HINT_INFO priorityHint;
|
||||
priorityHint.PriorityHint = IoPriorityHintLow;
|
||||
SetFileInformationByHandle(e.file_ptr->native_handle(),
|
||||
FileIoPriorityHintInfo, &priorityHint, sizeof(priorityHint));
|
||||
}
|
||||
#endif
|
||||
set_low_priority(e.file_ptr);
|
||||
#endif
|
||||
TORRENT_ASSERT(e.file_ptr->is_open());
|
||||
e.mode = m;
|
||||
@@ -189,6 +247,10 @@ namespace libtorrent
|
||||
std::string full_path = combine_path(p, fs.file_path(*fe));
|
||||
if (!e.file_ptr->open(full_path, m, ec))
|
||||
return boost::intrusive_ptr<file>();
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (m_low_prio_io)
|
||||
set_low_priority(e.file_ptr);
|
||||
#endif
|
||||
e.mode = m;
|
||||
e.key = st;
|
||||
m_files.insert(std::make_pair(std::make_pair(st, fs.file_index(*fe)), e));
|
||||
|
Reference in New Issue
Block a user