This commit is contained in:
@ -35,7 +35,7 @@ public:
|
|||||||
direct_open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
direct_open_file(std::uint64_t chunk_size, std::uint8_t chunk_timeout,
|
||||||
filesystem_item fsi, i_provider &provider);
|
filesystem_item fsi, i_provider &provider);
|
||||||
|
|
||||||
~direct_open_file() override = default;
|
~direct_open_file() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
direct_open_file() = delete;
|
direct_open_file() = delete;
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
std::uint8_t chunk_timeout, filesystem_item fsi,
|
std::uint8_t chunk_timeout, filesystem_item fsi,
|
||||||
i_provider &provider, std::size_t ring_size);
|
i_provider &provider, std::size_t ring_size);
|
||||||
|
|
||||||
~ring_buffer_open_file() override = default;
|
~ring_buffer_open_file() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ring_buffer_open_file() = delete;
|
ring_buffer_open_file() = delete;
|
||||||
@ -61,8 +61,6 @@ protected:
|
|||||||
on_chunk_downloaded(std::size_t chunk,
|
on_chunk_downloaded(std::size_t chunk,
|
||||||
const data_buffer &buffer) -> api_error override;
|
const data_buffer &buffer) -> api_error override;
|
||||||
|
|
||||||
void on_destroy() override;
|
|
||||||
|
|
||||||
[[nodiscard]] auto
|
[[nodiscard]] auto
|
||||||
use_buffer(std::size_t chunk,
|
use_buffer(std::size_t chunk,
|
||||||
std::function<api_error(const data_buffer &buffer)> func)
|
std::function<api_error(const data_buffer &buffer)> func)
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
filesystem_item fsi, i_provider &provider,
|
filesystem_item fsi, i_provider &provider,
|
||||||
std::size_t ring_size, bool disable_io);
|
std::size_t ring_size, bool disable_io);
|
||||||
|
|
||||||
~ring_file_base() override;
|
~ring_file_base() override = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr const auto min_ring_size{5U};
|
static constexpr const auto min_ring_size{5U};
|
||||||
@ -90,8 +90,6 @@ protected:
|
|||||||
return api_error::success;
|
return api_error::success;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void on_destroy() {}
|
|
||||||
|
|
||||||
[[nodiscard]] virtual auto
|
[[nodiscard]] virtual auto
|
||||||
use_buffer(std::size_t chunk,
|
use_buffer(std::size_t chunk,
|
||||||
std::function<api_error(const data_buffer &buffer)> func)
|
std::function<api_error(const data_buffer &buffer)> func)
|
||||||
|
@ -28,6 +28,8 @@ direct_open_file::direct_open_file(std::uint64_t chunk_size,
|
|||||||
: ring_file_base(chunk_size, chunk_timeout, fsi, provider, min_ring_size,
|
: ring_file_base(chunk_size, chunk_timeout, fsi, provider, min_ring_size,
|
||||||
true) {}
|
true) {}
|
||||||
|
|
||||||
|
direct_open_file::~direct_open_file() { close(); }
|
||||||
|
|
||||||
auto direct_open_file::handle_read_buffer(
|
auto direct_open_file::handle_read_buffer(
|
||||||
std::size_t chunk,
|
std::size_t chunk,
|
||||||
std::function<api_error(data_buffer &data)> func) -> api_error {
|
std::function<api_error(data_buffer &data)> func) -> api_error {
|
||||||
|
@ -40,6 +40,25 @@ ring_buffer_open_file::ring_buffer_open_file(std::string buffer_directory,
|
|||||||
utils::create_uuid_string(),
|
utils::create_uuid_string(),
|
||||||
})) {}
|
})) {}
|
||||||
|
|
||||||
|
ring_buffer_open_file::~ring_buffer_open_file() {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
close();
|
||||||
|
|
||||||
|
if (nf_) {
|
||||||
|
nf_->close();
|
||||||
|
nf_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (utils::file::file(get_source_path()).remove()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils::error::raise_api_path_error(
|
||||||
|
function_name, get_api_path(), get_source_path(),
|
||||||
|
utils::get_last_error_code(), "failed to delete file");
|
||||||
|
}
|
||||||
|
|
||||||
auto ring_buffer_open_file::handle_read_buffer(
|
auto ring_buffer_open_file::handle_read_buffer(
|
||||||
std::size_t /* chunk */,
|
std::size_t /* chunk */,
|
||||||
std::function<api_error(data_buffer &data)> func) -> api_error {
|
std::function<api_error(data_buffer &data)> func) -> api_error {
|
||||||
@ -91,25 +110,6 @@ auto ring_buffer_open_file::on_chunk_downloaded(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ring_buffer_open_file::on_destroy() {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
if (not nf_) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nf_->close();
|
|
||||||
nf_.reset();
|
|
||||||
|
|
||||||
if (utils::file::file(get_source_path()).remove()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
utils::error::raise_api_path_error(
|
|
||||||
function_name, get_api_path(), get_source_path(),
|
|
||||||
utils::get_last_error_code(), "failed to delete file");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ring_buffer_open_file::use_buffer(
|
auto ring_buffer_open_file::use_buffer(
|
||||||
std::size_t chunk,
|
std::size_t chunk,
|
||||||
std::function<api_error(const data_buffer &data)> func) -> api_error {
|
std::function<api_error(const data_buffer &data)> func) -> api_error {
|
||||||
|
@ -59,19 +59,6 @@ ring_file_base::ring_file_base(std::uint64_t chunk_size,
|
|||||||
ring_state_.set(0U, ring_state_.size(), false);
|
ring_state_.set(0U, ring_state_.size(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ring_file_base::~ring_file_base() {
|
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
|
||||||
|
|
||||||
close();
|
|
||||||
|
|
||||||
on_destroy();
|
|
||||||
|
|
||||||
if (reader_thread_) {
|
|
||||||
reader_thread_->join();
|
|
||||||
reader_thread_.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto ring_file_base::can_handle_file(std::uint64_t file_size,
|
auto ring_file_base::can_handle_file(std::uint64_t file_size,
|
||||||
std::size_t chunk_size,
|
std::size_t chunk_size,
|
||||||
std::size_t ring_size) -> bool {
|
std::size_t ring_size) -> bool {
|
||||||
@ -107,7 +94,14 @@ auto ring_file_base::close() -> bool {
|
|||||||
chunk_notify_.notify_all();
|
chunk_notify_.notify_all();
|
||||||
chunk_lock.unlock();
|
chunk_lock.unlock();
|
||||||
|
|
||||||
return open_file_base::close();
|
auto ret = open_file_base::close();
|
||||||
|
|
||||||
|
if (reader_thread_) {
|
||||||
|
reader_thread_->join();
|
||||||
|
reader_thread_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ring_file_base::download_chunk(std::size_t chunk,
|
auto ring_file_base::download_chunk(std::size_t chunk,
|
||||||
|
Reference in New Issue
Block a user