*** empty log message ***
This commit is contained in:
@@ -9,5 +9,5 @@ exe simple_client : simple_client.cpp ;
|
|||||||
exe dump_torrent : dump_torrent.cpp ;
|
exe dump_torrent : dump_torrent.cpp ;
|
||||||
exe make_torrent : make_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 {
|
namespace detail {
|
||||||
|
|
||||||
template<typename InputIterator>
|
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==last) throw std::runtime_error("incomplete UTF-8 sequence");
|
||||||
if(((*iter)&0xC0)!=0x80) throw std::runtime_error("invalid 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>
|
template<typename InputIterator>
|
||||||
static wchar_t decode_utf8(InputIterator &iter, InputIterator last) {
|
wchar_t decode_utf8(InputIterator &iter, InputIterator last)
|
||||||
|
{
|
||||||
wchar_t ret;
|
wchar_t ret;
|
||||||
|
|
||||||
if(((*iter)&0x80) == 0) {
|
if(((*iter)&0x80) == 0) {
|
||||||
@@ -64,19 +66,23 @@ static wchar_t decode_utf8(InputIterator &iter, InputIterator last) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator, typename OutputIterator>
|
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)
|
for(; first!=last; ++dest)
|
||||||
*dest=decode_utf8(first, last);
|
*dest=decode_utf8(first, last);
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator, typename OutputIterator>
|
template<typename InputIterator, typename OutputIterator>
|
||||||
static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
void encode_wchar(InputIterator iter, OutputIterator &dest)
|
||||||
if(*iter <= 0x007F) {
|
{
|
||||||
|
if(*iter <= 0x007F)
|
||||||
|
{
|
||||||
*dest=(char)*iter;
|
*dest=(char)*iter;
|
||||||
++dest;
|
++dest;
|
||||||
}
|
}
|
||||||
else if(*iter <= 0x07FF) {
|
else if(*iter <= 0x07FF)
|
||||||
|
{
|
||||||
*dest = (char)(
|
*dest = (char)(
|
||||||
0xC0 |
|
0xC0 |
|
||||||
((*iter & 0x07C0) >> 6)
|
((*iter & 0x07C0) >> 6)
|
||||||
@@ -89,7 +95,8 @@ static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
|||||||
);
|
);
|
||||||
++dest;
|
++dest;
|
||||||
}
|
}
|
||||||
else if(*iter <= 0xFFFF) {
|
else if(*iter <= 0xFFFF)
|
||||||
|
{
|
||||||
*dest = (char)(
|
*dest = (char)(
|
||||||
0xE0 |
|
0xE0 |
|
||||||
((*iter & 0xF000) >> 12)
|
((*iter & 0xF000) >> 12)
|
||||||
@@ -111,7 +118,8 @@ static void encode_wchar(InputIterator iter, OutputIterator &dest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename InputIterator, typename OutputIterator>
|
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)
|
for(; first!=last; ++first)
|
||||||
encode_wchar(first, dest);
|
encode_wchar(first, dest);
|
||||||
return 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();
|
wide.clear();
|
||||||
detail::utf8_wchar(utf8.begin(), utf8.end(), std::insert_iterator<std::wstring>(wide, wide.end()));
|
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;
|
std::wstring ret;
|
||||||
utf8_wchar(str, ret);
|
utf8_wchar(str, ret);
|
||||||
return 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();
|
utf8.clear();
|
||||||
detail::wchar_utf8(wide.begin(), wide.end(), std::insert_iterator<std::string>(utf8, utf8.end()));
|
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;
|
std::string ret;
|
||||||
wchar_utf8(str, ret);
|
wchar_utf8(str, ret);
|
||||||
return 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 <boost/filesystem/operations.hpp>
|
||||||
#include "libtorrent/file.hpp"
|
#include "libtorrent/file.hpp"
|
||||||
|
#include "libtorrent/utf8.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -79,6 +80,34 @@ namespace
|
|||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
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
|
namespace libtorrent
|
||||||
@@ -114,7 +143,7 @@ namespace libtorrent
|
|||||||
assert(path.is_complete());
|
assert(path.is_complete());
|
||||||
close();
|
close();
|
||||||
m_fd = ::open(
|
m_fd = ::open(
|
||||||
path.native_file_string().c_str()
|
utf8_native(path.native_file_string()).c_str()
|
||||||
, map_open_mode(mode)
|
, map_open_mode(mode)
|
||||||
, S_IREAD | S_IWRITE);
|
, S_IREAD | S_IWRITE);
|
||||||
if (m_fd == -1)
|
if (m_fd == -1)
|
||||||
|
@@ -923,19 +923,36 @@ namespace libtorrent
|
|||||||
throw protocol_error("invalid piece packet");
|
throw protocol_error("invalid piece packet");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_VERBOSE_LOGGING
|
|
||||||
using namespace boost::posix_time;
|
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;
|
|
||||||
|
|
||||||
|
piece_picker& picker = m_torrent->picker();
|
||||||
|
|
||||||
|
piece_block block_finished(p.piece, p.start / m_torrent->block_size());
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
for (i = m_download_queue.begin();
|
||||||
|
i != b; ++i)
|
||||||
|
{
|
||||||
|
#ifdef TORRENT_VERBOSE_LOGGING
|
||||||
(*m_logger) << to_simple_string(second_clock::universal_time())
|
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||||
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
|
<< " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
|
||||||
"b: " << i->block_index << " ] ***\n";
|
"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())
|
(*m_logger) << to_simple_string(second_clock::universal_time())
|
||||||
<< " <== PIECE [ piece: " << p.piece << " | "
|
<< " <== PIECE [ piece: " << p.piece << " | "
|
||||||
"b: " << p.start / m_torrent->block_size() << " | "
|
"b: " << p.start / m_torrent->block_size() << " | "
|
||||||
@@ -943,23 +960,11 @@ namespace libtorrent
|
|||||||
"l: " << p.length << " ]\n";
|
"l: " << p.length << " ]\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
piece_picker& picker = m_torrent->picker();
|
// remove the request that just finished
|
||||||
piece_block block_finished(p.piece, p.start / m_torrent->block_size());
|
// from the download queue plus the
|
||||||
|
// skipped blocks.
|
||||||
// if the block we got is already finished, then ignore it
|
m_download_queue.erase(m_download_queue.begin()
|
||||||
if (picker.is_finished(block_finished)) return;
|
, boost::next(b));
|
||||||
|
|
||||||
std::deque<piece_block>::iterator b
|
|
||||||
= std::find(
|
|
||||||
m_download_queue.begin()
|
|
||||||
, m_download_queue.end()
|
|
||||||
, block_finished);
|
|
||||||
|
|
||||||
if (b != m_download_queue.end())
|
|
||||||
{
|
|
||||||
// pop the request that just finished
|
|
||||||
// from the download queue
|
|
||||||
m_download_queue.erase(b);
|
|
||||||
}
|
}
|
||||||
else
|
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);
|
m_torrent->filesystem().write(&m_recv_buffer[9], p.piece, p.start, p.length);
|
||||||
|
|
||||||
bool was_seed = m_torrent->is_seed();
|
bool was_seed = m_torrent->is_seed();
|
||||||
|
Reference in New Issue
Block a user