forked from premiere/premiere-libtorrent
*** empty log message ***
This commit is contained in:
parent
614d459f87
commit
5914b3400f
|
@ -99,7 +99,7 @@ namespace libtorrent
|
|||
size_type write(const char*, size_type num_bytes);
|
||||
size_type read(char*, size_type num_bytes);
|
||||
|
||||
void seek(size_type pos, seek_mode m);
|
||||
void seek(size_type pos, seek_mode m = begin);
|
||||
size_type tell();
|
||||
|
||||
private:
|
||||
|
|
|
@ -40,7 +40,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <boost/thread.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/opaque_value_ptr.hpp"
|
||||
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2003, Arvid Norberg
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
#include "libtorrent/file.hpp"
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::ios_base::openmode map_open_mode(fs::path const& p, int m)
|
||||
{
|
||||
std::ios_base::openmode ret(std::ios_base::binary);
|
||||
if ((m & 1) || fs::exists(p)) ret |= std::ios_base::in;
|
||||
if (m & 2) ret |= std::ios_base::out;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
||||
const file::open_mode file::in(1);
|
||||
const file::open_mode file::out(2);
|
||||
|
||||
const file::seek_mode file::begin(1);
|
||||
const file::seek_mode file::end(2);
|
||||
|
||||
struct file::impl
|
||||
{
|
||||
impl() {}
|
||||
|
||||
impl(fs::path const& path, int mode)
|
||||
: m_file(path, map_open_mode(path, mode))
|
||||
{
|
||||
if (m_file.fail())
|
||||
throw file_error("open failed '" + path.native_file_string() + "'");
|
||||
}
|
||||
|
||||
void open(fs::path const& path, int mode)
|
||||
{
|
||||
if (m_file.is_open()) m_file.close();
|
||||
m_file.clear();
|
||||
m_file.open(path, map_open_mode(path, mode));
|
||||
|
||||
if (m_file.fail())
|
||||
throw file_error("open failed '" + path.native_file_string() + "'");
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
m_file.close();
|
||||
}
|
||||
|
||||
size_type read(char* buf, size_type num_bytes)
|
||||
{
|
||||
// TODO: split the read if num_bytes > 2 gig
|
||||
m_file.read(buf, num_bytes);
|
||||
return m_file.gcount();
|
||||
}
|
||||
|
||||
size_type write(const char* buf, size_type num_bytes)
|
||||
{
|
||||
// TODO: split the write if num_bytes > 2 gig
|
||||
m_file.write(buf, num_bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void seek(size_type offset, int m)
|
||||
{
|
||||
std::ios_base::seekdir d =
|
||||
(m == 1) ? std::ios_base::beg : std::ios_base::end;
|
||||
m_file.seekp(offset, d);
|
||||
m_file.seekg(offset, d);
|
||||
}
|
||||
|
||||
size_type tell()
|
||||
{
|
||||
return std::max(m_file.tellg(), m_file.tellp());
|
||||
}
|
||||
|
||||
fs::fstream m_file;
|
||||
};
|
||||
|
||||
|
||||
file::file() : m_impl(new impl()) {}
|
||||
|
||||
file::file(boost::filesystem::path const& p, file::open_mode m)
|
||||
: m_impl(new impl(p, m.m_mask))
|
||||
{}
|
||||
|
||||
file::~file() {}
|
||||
|
||||
void file::open(boost::filesystem::path const& p, file::open_mode m)
|
||||
{
|
||||
m_impl->open(p, m.m_mask);
|
||||
}
|
||||
|
||||
void file::close()
|
||||
{
|
||||
m_impl->close();
|
||||
}
|
||||
|
||||
file::size_type file::write(const char* buf, file::size_type num_bytes)
|
||||
{
|
||||
return m_impl->write(buf, num_bytes);
|
||||
}
|
||||
|
||||
file::size_type file::read(char* buf, file::size_type num_bytes)
|
||||
{
|
||||
return m_impl->read(buf, num_bytes);
|
||||
}
|
||||
|
||||
void file::seek(file::size_type pos, file::seek_mode m)
|
||||
{
|
||||
m_impl->seek(pos, m.m_val);
|
||||
}
|
||||
|
||||
file::size_type file::tell()
|
||||
{
|
||||
return m_impl->tell();
|
||||
}
|
||||
|
||||
}
|
|
@ -624,14 +624,6 @@ namespace libtorrent
|
|||
|
||||
(*m_logger) << " *** SKIPPED_PIECE [ piece: " << i->piece_index << " | "
|
||||
"b: " << i->block_index << " ] ***\n";
|
||||
if (m_torrent->alerts().should_post(alert::debug))
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "skipped piece: " << i->piece_index << " b: " << i->block_index;
|
||||
m_torrent->alerts().post_alert(
|
||||
peer_error_alert(get_peer_id(), s.str()));
|
||||
|
||||
}
|
||||
}
|
||||
(*m_logger) << " <== PIECE [ piece: " << p.piece << " | "
|
||||
"b: " << p.start / m_torrent->block_size() << " | "
|
||||
|
|
|
@ -33,7 +33,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <ios>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
//#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
|
@ -41,7 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/filesystem/convenience.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
//#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
|
@ -196,17 +196,23 @@ namespace libtorrent {
|
|||
file_offset -= file_iter->size;
|
||||
++file_iter;
|
||||
}
|
||||
|
||||
/*
|
||||
fs::ifstream in(
|
||||
m_pimpl->save_path / file_iter->path / file_iter->filename
|
||||
, std::ios_base::binary
|
||||
);
|
||||
*/
|
||||
file in(
|
||||
m_pimpl->save_path / file_iter->path / file_iter->filename
|
||||
, file::in);
|
||||
|
||||
assert(file_offset < file_iter->size);
|
||||
|
||||
in.seekg(file_offset);
|
||||
// in.seekg(file_offset);
|
||||
in.seek(file_offset);
|
||||
|
||||
assert(size_type(in.tellg()) == file_offset);
|
||||
// assert(size_type(in.tellg()) == file_offset);
|
||||
assert(size_type(in.tell()) == file_offset);
|
||||
|
||||
size_type left_to_read = size;
|
||||
size_type slot_size = m_pimpl->info.piece_size(slot);
|
||||
|
@ -227,9 +233,10 @@ namespace libtorrent {
|
|||
|
||||
assert(read_bytes > 0);
|
||||
|
||||
in.read(buf + buf_pos, read_bytes);
|
||||
// in.read(buf + buf_pos, read_bytes);
|
||||
// int actual_read = in.gcount();
|
||||
int actual_read = in.read(buf + buf_pos, read_bytes);
|
||||
|
||||
int actual_read = in.gcount();
|
||||
assert(read_bytes == actual_read);
|
||||
|
||||
left_to_read -= read_bytes;
|
||||
|
@ -243,9 +250,10 @@ namespace libtorrent {
|
|||
fs::path path = m_pimpl->save_path / file_iter->path / file_iter->filename;
|
||||
|
||||
file_offset = 0;
|
||||
in.close();
|
||||
in.clear();
|
||||
in.open(path, std::ios_base::binary);
|
||||
// in.close();
|
||||
// in.clear();
|
||||
// in.open(path, std::ios_base::binary);
|
||||
in.open(path, file::in);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -274,18 +282,23 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
fs::path path(m_pimpl->save_path / file_iter->path / file_iter->filename);
|
||||
/*
|
||||
fs::ofstream out;
|
||||
|
||||
if (fs::exists(path))
|
||||
out.open(path, std::ios_base::binary | std::ios_base::in);
|
||||
else
|
||||
out.open(path, std::ios_base::binary);
|
||||
*/
|
||||
file out(path, file::out);
|
||||
|
||||
assert(file_offset < file_iter->size);
|
||||
|
||||
out.seekp(file_offset);
|
||||
// out.seekp(file_offset);
|
||||
out.seek(file_offset);
|
||||
|
||||
assert(file_offset == out.tellp());
|
||||
// assert(file_offset == out.tellp());
|
||||
assert(file_offset == out.tell());
|
||||
|
||||
size_type left_to_write = size;
|
||||
size_type slot_size = m_pimpl->info.piece_size(slot);
|
||||
|
@ -327,6 +340,7 @@ namespace libtorrent {
|
|||
fs::path path = m_pimpl->save_path / file_iter->path / file_iter->filename;
|
||||
|
||||
file_offset = 0;
|
||||
/*
|
||||
out.close();
|
||||
out.clear();
|
||||
|
||||
|
@ -334,6 +348,8 @@ namespace libtorrent {
|
|||
out.open(path, std::ios_base::binary | std::ios_base::in);
|
||||
else
|
||||
out.open(path, std::ios_base::binary);
|
||||
*/
|
||||
out.open(path, file::out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -603,7 +619,8 @@ namespace libtorrent {
|
|||
}
|
||||
|
||||
bool changed_file = true;
|
||||
fs::ifstream in;
|
||||
// fs::ifstream in;
|
||||
file in;
|
||||
|
||||
std::vector<char> piece_data(m_info.piece_length());
|
||||
std::size_t piece_offset = 0;
|
||||
|
@ -646,6 +663,7 @@ namespace libtorrent {
|
|||
|
||||
if (changed_file)
|
||||
{
|
||||
/*
|
||||
in.close();
|
||||
in.clear();
|
||||
in.open(path, std::ios_base::binary);
|
||||
|
@ -664,6 +682,22 @@ namespace libtorrent {
|
|||
filesize = in.tellg();
|
||||
in.seekg(seek_into_next, std::ios_base::beg);
|
||||
}
|
||||
*/
|
||||
try
|
||||
{
|
||||
changed_file = false;
|
||||
bytes_current_read = seek_into_next;
|
||||
in.open(path, file::in);
|
||||
|
||||
in.seek(0, file::end);
|
||||
filesize = in.tell();
|
||||
in.seek(seek_into_next);
|
||||
}
|
||||
catch (file_error&)
|
||||
{
|
||||
filesize = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// we are at the start of a new piece
|
||||
|
@ -675,8 +709,9 @@ namespace libtorrent {
|
|||
|
||||
if (filesize > 0)
|
||||
{
|
||||
in.read(&piece_data[piece_offset], bytes_to_read);
|
||||
bytes_read = in.gcount();
|
||||
// in.read(&piece_data[piece_offset], bytes_to_read);
|
||||
// bytes_read = in.gcount();
|
||||
bytes_read = in.read(&piece_data[piece_offset], bytes_to_read);
|
||||
}
|
||||
|
||||
bytes_current_read += bytes_read;
|
||||
|
|
Loading…
Reference in New Issue