forked from premiere/premiere-libtorrent
*** empty log message ***
This commit is contained in:
parent
d95b37fb33
commit
57144ea15d
|
@ -9,5 +9,5 @@ exe simple_client : simple_client.cpp ;
|
|||
exe dump_torrent : dump_torrent.cpp ;
|
||||
exe make_torrent : make_torrent.cpp ;
|
||||
|
||||
stage . : dump_torrent make_torrent simple_client client_test ;
|
||||
# stage . : dump_torrent make_torrent simple_client client_test ;
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ namespace libtorrent {
|
|||
namespace detail {
|
||||
|
||||
template<typename InputIterator>
|
||||
static wchar_t decode_utf8_mb(InputIterator &iter, InputIterator last) {
|
||||
wchar_t decode_utf8_mb(InputIterator &iter, InputIterator last)
|
||||
{
|
||||
if(iter==last) throw std::runtime_error("incomplete UTF-8 sequence");
|
||||
if(((*iter)&0xC0)!=0x80) throw std::runtime_error("invalid UTF-8 sequence");
|
||||
|
||||
|
@ -39,7 +40,8 @@ static wchar_t decode_utf8_mb(InputIterator &iter, InputIterator last) {
|
|||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
static wchar_t decode_utf8(InputIterator &iter, InputIterator last) {
|
||||
wchar_t decode_utf8(InputIterator &iter, InputIterator last)
|
||||
{
|
||||
wchar_t ret;
|
||||
|
||||
if(((*iter)&0x80) == 0) {
|
||||
|
@ -64,19 +66,23 @@ static wchar_t decode_utf8(InputIterator &iter, InputIterator last) {
|
|||
}
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
static OutputIterator utf8_wchar(InputIterator first, InputIterator last, OutputIterator dest) {
|
||||
OutputIterator utf8_wchar(InputIterator first, InputIterator last, OutputIterator dest)
|
||||
{
|
||||
for(; first!=last; ++dest)
|
||||
*dest=decode_utf8(first, last);
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
||||
if(*iter <= 0x007F) {
|
||||
void encode_wchar(InputIterator iter, OutputIterator &dest)
|
||||
{
|
||||
if(*iter <= 0x007F)
|
||||
{
|
||||
*dest=(char)*iter;
|
||||
++dest;
|
||||
}
|
||||
else if(*iter <= 0x07FF) {
|
||||
else if(*iter <= 0x07FF)
|
||||
{
|
||||
*dest = (char)(
|
||||
0xC0 |
|
||||
((*iter & 0x07C0) >> 6)
|
||||
|
@ -89,7 +95,8 @@ static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
|||
);
|
||||
++dest;
|
||||
}
|
||||
else if(*iter <= 0xFFFF) {
|
||||
else if(*iter <= 0xFFFF)
|
||||
{
|
||||
*dest = (char)(
|
||||
0xE0 |
|
||||
((*iter & 0xF000) >> 12)
|
||||
|
@ -111,7 +118,8 @@ static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
|||
}
|
||||
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
static OutputIterator wchar_utf8(InputIterator first, InputIterator last, OutputIterator dest) {
|
||||
OutputIterator wchar_utf8(InputIterator first, InputIterator last, OutputIterator dest)
|
||||
{
|
||||
for(; first!=last; ++first)
|
||||
encode_wchar(first, dest);
|
||||
return dest;
|
||||
|
@ -119,23 +127,27 @@ static OutputIterator wchar_utf8(InputIterator first, InputIterator last, Output
|
|||
|
||||
}
|
||||
|
||||
static void utf8_wchar(const std::string &utf8, std::wstring &wide) {
|
||||
void utf8_wchar(const std::string &utf8, std::wstring &wide)
|
||||
{
|
||||
wide.clear();
|
||||
detail::utf8_wchar(utf8.begin(), utf8.end(), std::insert_iterator<std::wstring>(wide, wide.end()));
|
||||
}
|
||||
|
||||
static std::wstring utf8_wchar(const std::string &str) {
|
||||
std::wstring utf8_wchar(const std::string &str)
|
||||
{
|
||||
std::wstring ret;
|
||||
utf8_wchar(str, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wchar_utf8(const std::wstring &wide, std::string &utf8) {
|
||||
void wchar_utf8(const std::wstring &wide, std::string &utf8)
|
||||
{
|
||||
utf8.clear();
|
||||
detail::wchar_utf8(wide.begin(), wide.end(), std::insert_iterator<std::string>(utf8, utf8.end()));
|
||||
}
|
||||
|
||||
static std::string wchar_utf8(const std::wstring &str) {
|
||||
std::string wchar_utf8(const std::wstring &str)
|
||||
{
|
||||
std::string ret;
|
||||
wchar_utf8(str, ret);
|
||||
return ret;
|
||||
|
|
31
src/file.cpp
31
src/file.cpp
|
@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/utf8.hpp"
|
||||
#include <sstream>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -79,6 +80,34 @@ namespace
|
|||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
std::string utf8_native(std::string const& s)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::wstring ws;
|
||||
libtorrent::utf8_wchar(s, ws);
|
||||
std::size_t size = wcstombs(0, ws.c_str(), 0);
|
||||
if (size == std::size_t(-1)) return s;
|
||||
std::string ret;
|
||||
ret.resize(size);
|
||||
size = wcstombs(&ret[0], ws.c_str(), size + 1);
|
||||
ret.resize(size);
|
||||
return ret;
|
||||
}
|
||||
catch(std::exception)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
}
|
||||
#else
|
||||
std::string utf8_native(std::string const& s)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
namespace libtorrent
|
||||
|
@ -114,7 +143,7 @@ namespace libtorrent
|
|||
assert(path.is_complete());
|
||||
close();
|
||||
m_fd = ::open(
|
||||
path.native_file_string().c_str()
|
||||
utf8_native(path.native_file_string()).c_str()
|
||||
, map_open_mode(mode)
|
||||
, S_IREAD | S_IWRITE);
|
||||
if (m_fd == -1)
|
||||
|
|
|
@ -923,43 +923,48 @@ namespace libtorrent
|
|||
throw protocol_error("invalid piece packet");
|
||||
}
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
using namespace boost::posix_time;
|
||||
for (std::deque<piece_block>::iterator i = m_download_queue.begin();
|
||||
i != m_download_queue.end(); ++i)
|
||||
{
|
||||
if (i->piece_index == p.piece
|
||||
&& i->block_index == p.start / m_torrent->block_size())
|
||||
break;
|
||||
|
||||
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
|
||||
"b: " << i->block_index << " ] ***\n";
|
||||
}
|
||||
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||
<< " <== PIECE [ piece: " << p.piece << " | "
|
||||
"b: " << p.start / m_torrent->block_size() << " | "
|
||||
"s: " << p.start << " | "
|
||||
"l: " << p.length << " ]\n";
|
||||
#endif
|
||||
|
||||
piece_picker& picker = m_torrent->picker();
|
||||
|
||||
piece_block block_finished(p.piece, p.start / m_torrent->block_size());
|
||||
|
||||
// if the block we got is already finished, then ignore it
|
||||
if (picker.is_finished(block_finished)) return;
|
||||
|
||||
std::deque<piece_block>::iterator b
|
||||
= std::find(
|
||||
m_download_queue.begin()
|
||||
, m_download_queue.end()
|
||||
, block_finished);
|
||||
|
||||
|
||||
std::deque<piece_block>::iterator i;
|
||||
|
||||
if (b != m_download_queue.end())
|
||||
{
|
||||
// pop the request that just finished
|
||||
// from the download queue
|
||||
m_download_queue.erase(b);
|
||||
for (i = m_download_queue.begin();
|
||||
i != b; ++i)
|
||||
{
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
|
||||
"b: " << i->block_index << " ] ***\n";
|
||||
#endif
|
||||
// since this piece was skipped, clear it and allow it to
|
||||
// be requested from other peers
|
||||
picker.abort_download(*i);
|
||||
}
|
||||
|
||||
#ifdef TORRENT_VERBOSE_LOGGING
|
||||
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||
<< " <== PIECE [ piece: " << p.piece << " | "
|
||||
"b: " << p.start / m_torrent->block_size() << " | "
|
||||
"s: " << p.start << " | "
|
||||
"l: " << p.length << " ]\n";
|
||||
#endif
|
||||
|
||||
// remove the request that just finished
|
||||
// from the download queue plus the
|
||||
// skipped blocks.
|
||||
m_download_queue.erase(m_download_queue.begin()
|
||||
, boost::next(b));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -990,6 +995,9 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
// if the block we got is already finished, then ignore it
|
||||
if (picker.is_finished(block_finished)) return;
|
||||
|
||||
m_torrent->filesystem().write(&m_recv_buffer[9], p.piece, p.start, p.length);
|
||||
|
||||
bool was_seed = m_torrent->is_seed();
|
||||
|
|
Loading…
Reference in New Issue