refactor
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-12-22 11:46:30 -06:00
parent 9d873c0147
commit ac66240fac
4 changed files with 18 additions and 4 deletions

View File

@ -47,6 +47,7 @@ public:
private:
std::size_t total_chunks_;
stop_type stop_requested_{false};
protected:
[[nodiscard]] auto is_download_complete() const -> bool override {
@ -54,6 +55,8 @@ protected:
}
public:
auto close() -> bool override;
[[nodiscard]] auto is_complete() const -> bool override { return true; }
[[nodiscard]] auto is_write_supported() const -> bool override {

View File

@ -63,6 +63,7 @@ private:
std::size_t current_chunk_{};
std::size_t first_chunk_{};
std::size_t last_chunk_;
stop_type stop_requested_{false};
private:
auto download_chunk(std::size_t chunk) -> api_error;
@ -77,6 +78,8 @@ protected:
}
public:
auto close() -> bool override;
void forward(std::size_t count);
[[nodiscard]] auto get_current_chunk() const -> std::size_t {

View File

@ -36,6 +36,11 @@ direct_open_file::direct_open_file(std::uint64_t chunk_size,
direct_open_file::~direct_open_file() { close(); }
auto direct_open_file::close() -> bool {
stop_requested_ = true;
return open_file_base::close();
}
auto direct_open_file::read(std::size_t read_size, std::uint64_t read_offset,
data_buffer &data) -> api_error {
if (fsi_.directory) {
@ -49,9 +54,8 @@ auto direct_open_file::read(std::size_t read_size, std::uint64_t read_offset,
return api_error::success;
}
stop_type stop_requested{false};
auto res = provider_.read_file_bytes(fsi_.api_path, read_size, read_offset,
data, stop_requested);
data, stop_requested_);
reset_timeout();
return res;

View File

@ -103,6 +103,11 @@ ring_buffer_open_file::~ring_buffer_open_file() {
}
}
auto ring_buffer_open_file::close() -> bool {
stop_requested_ = true;
return open_file_base::close();
}
auto ring_buffer_open_file::download_chunk(std::size_t chunk) -> api_error {
unique_mutex_lock chunk_lock(chunk_mtx_);
if (active_downloads_.find(chunk) != active_downloads_.end()) {
@ -123,10 +128,9 @@ auto ring_buffer_open_file::download_chunk(std::size_t chunk) -> api_error {
data_buffer buffer((chunk == (total_chunks_ - 1U)) ? last_chunk_size_
: chunk_size_);
stop_type stop_requested = !!ring_state_[chunk % ring_state_.size()];
auto res =
provider_.read_file_bytes(fsi_.api_path, buffer.size(),
chunk * chunk_size_, buffer, stop_requested);
chunk * chunk_size_, buffer, stop_requested_);
if (res == api_error::success) {
res = do_io([&]() -> api_error {
std::size_t bytes_written{};