diff options
author | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-10-06 13:57:39 +0800 |
commit | dfe62dcf8bcefc523b466e127c3edc4dc2756629 (patch) | |
tree | 1c751a14ba0da07ca2ff805633f97568060aa4c9 /include/cru/common/io/AutoReadStream.h | |
parent | f51eb955e188858272230a990565931e7403f23b (diff) | |
download | cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.gz cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.tar.bz2 cru-dfe62dcf8bcefc523b466e127c3edc4dc2756629.zip |
Rename common to base.
Diffstat (limited to 'include/cru/common/io/AutoReadStream.h')
-rw-r--r-- | include/cru/common/io/AutoReadStream.h | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/include/cru/common/io/AutoReadStream.h b/include/cru/common/io/AutoReadStream.h deleted file mode 100644 index 759d5026..00000000 --- a/include/cru/common/io/AutoReadStream.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include "BufferStream.h" -#include "Stream.h" - -#include <mutex> -#include <thread> - -namespace cru::io { -struct AutoReadStreamOptions { - /** - * @brief Will be passed to BufferStreamOptions::block_size. - */ - Index block_size = 0; - - /** - * @brief Will be passed to BufferStreamOptions::total_size_limit. - */ - Index total_size_limit = 0; - - BufferStreamOptions GetBufferStreamOptions() const { - BufferStreamOptions options; - options.block_size = block_size; - options.total_size_limit = total_size_limit; - return options; - } -}; - -/** - * @brief A stream that wraps another stream and auto read it into a buffer in a - * background thread. - */ -class CRU_BASE_API AutoReadStream : public Stream { - public: - /** - * @brief Wrap a stream and auto read it in background. - * @param stream The stream to auto read. - * @param auto_delete Whether to delete the stream object in destructor. - * @param options Options to modify the behavior. - */ - AutoReadStream( - Stream* stream, bool auto_delete, - const AutoReadStreamOptions& options = AutoReadStreamOptions()); - - ~AutoReadStream() override; - - public: - CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE - - void BeginToDrop(bool auto_delete = true); - - protected: - Index DoRead(std::byte* buffer, Index offset, Index size) override; - Index DoWrite(const std::byte* buffer, Index offset, Index size) override; - void DoFlush() override; - - private: - void DoClose(); - - void BackgroundThreadRun(); - - private: - Stream* stream_; - bool auto_delete_; - - Index size_per_read_; - std::unique_ptr<BufferStream> buffer_stream_; - std::mutex buffer_stream_mutex_; - - std::thread background_thread_; -}; -} // namespace cru::io |