diff options
author | crupest <crupest@outlook.com> | 2024-06-24 00:06:25 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2024-10-04 19:55:33 +0800 |
commit | f51eb955e188858272230a990565931e7403f23b (patch) | |
tree | 04de484bfcd056b6eea56c13c42cce83315c448f /src/common/io/BufferStream.cpp | |
parent | 1b30150ab79ff1338f209a8ddb54b3dc60cfb599 (diff) | |
download | cru-f51eb955e188858272230a990565931e7403f23b.tar.gz cru-f51eb955e188858272230a990565931e7403f23b.tar.bz2 cru-f51eb955e188858272230a990565931e7403f23b.zip |
HALF WORK: Stream refactor.
TODO: Complete refactor of BufferStream and AutoReadStream.
NEED TEST: BufferStream, AutoReadStream, SubProcess.
Diffstat (limited to 'src/common/io/BufferStream.cpp')
-rw-r--r-- | src/common/io/BufferStream.cpp | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/src/common/io/BufferStream.cpp b/src/common/io/BufferStream.cpp index 242396cd..73e5719b 100644 --- a/src/common/io/BufferStream.cpp +++ b/src/common/io/BufferStream.cpp @@ -2,25 +2,17 @@ #include "cru/common/io/Stream.h" namespace cru::io { -BufferStream::BufferStream(const BufferStreamOptions& options) { +BufferStream::BufferStream(const BufferStreamOptions& options) + : Stream(false, true, true) { block_size_ = options.GetBlockSizeOrDefault(); max_block_count_ = options.GetMaxBlockCount(); eof_ = false; } -BufferStream::~BufferStream() {} +BufferStream::~BufferStream() { DoClose(); } -bool BufferStream::CanSeek() { return false; } - -Index BufferStream::Seek(Index offset, SeekOrigin origin) { - throw StreamOperationNotSupportedException( - u"BufferStream does not support seeking."); -} - -bool BufferStream::CanRead() { return true; } - -Index BufferStream::Read(std::byte* buffer, Index offset, Index size) { +Index BufferStream::DoRead(std::byte* buffer, Index offset, Index size) { std::unique_lock lock(mutex_); condition_variable_.wait(lock, @@ -56,9 +48,7 @@ Index BufferStream::Read(std::byte* buffer, Index offset, Index size) { return read; } -bool BufferStream::CanWrite() { return true; } - -Index BufferStream::Write(const std::byte* buffer, Index offset, Index size) { +Index BufferStream::DoWrite(const std::byte* buffer, Index offset, Index size) { std::unique_lock lock(mutex_); if (eof_) { @@ -115,4 +105,5 @@ void BufferStream::SetEof() { } } +void BufferStream::DoClose() { CRU_STREAM_BEGIN_CLOSE } } // namespace cru::io |