added character-set build feature (only effective on windows). Made storage build with win32/unicode and newer versions of boost. optimized allocate_slots

This commit is contained in:
Arvid Norberg 2007-04-18 19:12:30 +00:00
parent 4c8e8470cd
commit 88d6f7a4c9
5 changed files with 50 additions and 24 deletions

View File

@ -21,19 +21,19 @@ use-project /boost : $(BOOST_ROOT) ;
feature logging : none default verbose : composite propagated symmetric link-incompatible ;
feature.compose <logging>none : ;
feature.compose <logging>default : <define>TORRENT_LOGGING ;
feature.compose <logging>verbose : <define>TORRENT_VERBOSE_LOGGING ;
feature dht-support : on off logging : composite propagated symmetric link-incompatible ;
feature.compose <dht-support>on : ;
feature.compose <dht-support>off : <define>TORRENT_DISABLE_DHT ;
feature.compose <dht-support>logging : <define>TORRENT_DHT_VERBOSE_LOGGING ;
feature openssl : off on : composite propagated symmetric link-incompatible ;
feature.compose <openssl>off : ;
feature.compose <openssl>on : <define>TORRENT_USE_OPENSSL ;
feature character-set : ansi unicode : composite propagated link-incompatible ;
feature.compose <character-set>unicode : <define>_UNICODE <define>UNICODE ;
SOURCES =
allocate_resources
alert

View File

@ -226,6 +226,21 @@ Build features:
| | * ``profile`` - builds libtorrent with profile |
| | information. |
+------------------------+----------------------------------------------------+
| ``openssl`` | * ``on`` - openssl will be used instead of the |
| | public domain SHA-1 implementation shipped with |
| | libtorrent. ``crypto.lib`` or ``libcrypto.a`` |
| | will be required for linking. |
| | * ``off`` - the shipped SHA-1 implementation will |
| | be used, and there will be no dependency on |
| | openssl. |
+------------------------+----------------------------------------------------+
| ``character-set`` | This setting will only have an affect on windows. |
| | Other platforms are expected to support UTF-8. |
| | * ``ansi`` - The ansi version of the win32 API is |
| | used. |
| | * ``unicode`` - The unicode version of the win32 |
| | API is used. |
+------------------------+----------------------------------------------------+
The ``variant`` feature is *implicit*, which means you don't need to specify
the name of the feature, just the value.

View File

@ -139,7 +139,7 @@ namespace libtorrent
bool verify_resume_data(entry& rd, std::string& error);
bool is_allocating() const;
bool allocate_slots(int num_slots);
bool allocate_slots(int num_slots, bool abort_on_disk = false);
void mark_failed(int index);
unsigned long piece_crc(

View File

@ -169,14 +169,13 @@ namespace libtorrent
#endif
if (new_handle == INVALID_HANDLE_VALUE)
{
std::stringstream s;
throw_exception(file_name);
}
// try to make the file sparse if supported
DWORD temp;
::DeviceIoControl(new_handle, FSCTL_SET_SPARSE, 0, 0
int ret = ::DeviceIoControl(new_handle, FSCTL_SET_SPARSE, 0, 0
, 0, 0, &temp, 0);
if (ret == 0)
throw_exception(file_name);
// will only close old file if the open succeeded
close();
m_file_handle = new_handle;

View File

@ -118,7 +118,9 @@ namespace libtorrent
}
}
}
#endif
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
namespace
{
using libtorrent::safe_convert;
@ -254,7 +256,7 @@ namespace libtorrent
try
{
path f = p / i->path;
#if defined(_WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
size = file_size_win(f);
time = last_write_time_win(f);
#else
@ -291,7 +293,7 @@ namespace libtorrent
try
{
path f = p / i->path;
#if defined(_WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
size = file_size_win(f);
time = last_write_time_win(f);
#else
@ -462,7 +464,7 @@ namespace libtorrent
save_path = complete(save_path);
#if defined(_WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
std::wstring wsave_path(safe_convert(save_path.native_file_string()));
if (!exists_win(save_path))
{
@ -486,7 +488,7 @@ namespace libtorrent
try
{
#if defined(_WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
rename_win(old_path, new_path);
#else
rename(old_path, new_path);
@ -876,7 +878,7 @@ namespace libtorrent
void release_files();
bool allocate_slots(int num_slots);
bool allocate_slots(int num_slots, bool abort_on_disk = false);
void mark_failed(int index);
unsigned long piece_crc(
int slot_index
@ -1499,13 +1501,20 @@ namespace libtorrent
// final position.
assert(!m_unallocated_slots.empty());
// if we're not filling the allocation
// just make sure we move the current pieces
// into place, and just skip all other
// allocation
// allocate_slots returns true if it had to
// move any data
while (!m_unallocated_slots.empty() && !allocate_slots(1));
if (!m_fill_mode)
{
// if we're not filling the allocation
// just make sure we move the current pieces
// into place, and just skip all other
// allocation
// allocate_slots returns true if it had to
// move any data
allocate_slots(m_unallocated_slots.size(), true);
}
else
{
allocate_slots(1);
}
return std::make_pair(false, 1.f - (float)m_unallocated_slots.size()
/ (float)m_slot_to_piece.size());
@ -1529,7 +1538,7 @@ namespace libtorrent
if (dir == last_path) continue;
last_path = dir;
#if defined(_WIN32) && defined(UNICODE)
#if defined(_WIN32) && defined(UNICODE) && BOOST_VERSION < 13400
if (!exists_win(last_path))
create_directories_win(last_path);
#else
@ -1997,7 +2006,7 @@ namespace libtorrent
}
bool piece_manager::impl::allocate_slots(int num_slots)
bool piece_manager::impl::allocate_slots(int num_slots, bool abort_on_disk)
{
assert(num_slots > 0);
@ -2034,6 +2043,7 @@ namespace libtorrent
assert(m_piece_to_slot[pos] >= 0);
m_storage->read(&buffer[0], m_piece_to_slot[pos], 0
, static_cast<int>(m_info.piece_size(pos)));
std::cerr << "reading" << std::endl;
new_free_slot = m_piece_to_slot[pos];
m_slot_to_piece[pos] = pos;
m_piece_to_slot[pos] = pos;
@ -2045,8 +2055,10 @@ namespace libtorrent
if (write_back || m_fill_mode)
{
std::cerr << "writing" << std::endl;
m_storage->write(&buffer[0], pos, 0, static_cast<int>(m_info.piece_size(pos)));
written = true;
if (abort_on_disk) return true;
}
}
@ -2054,9 +2066,9 @@ namespace libtorrent
return written;
}
bool piece_manager::allocate_slots(int num_slots)
bool piece_manager::allocate_slots(int num_slots, bool abort_on_disk)
{
return m_pimpl->allocate_slots(num_slots);
return m_pimpl->allocate_slots(num_slots, abort_on_disk);
}
path const& piece_manager::save_path() const