aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common/platform/unix
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-06-24 00:06:25 +0800
committercrupest <crupest@outlook.com>2024-10-04 19:55:33 +0800
commitf51eb955e188858272230a990565931e7403f23b (patch)
tree04de484bfcd056b6eea56c13c42cce83315c448f /include/cru/common/platform/unix
parent1b30150ab79ff1338f209a8ddb54b3dc60cfb599 (diff)
downloadcru-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 'include/cru/common/platform/unix')
-rw-r--r--include/cru/common/platform/unix/UnixFileStream.h27
1 files changed, 7 insertions, 20 deletions
diff --git a/include/cru/common/platform/unix/UnixFileStream.h b/include/cru/common/platform/unix/UnixFileStream.h
index 43615776..8021f21a 100644
--- a/include/cru/common/platform/unix/UnixFileStream.h
+++ b/include/cru/common/platform/unix/UnixFileStream.h
@@ -17,36 +17,23 @@ class UnixFileStream : public io::Stream {
UnixFileStream(const char* path, int oflag, mode_t mode = 0660);
UnixFileStream(int fd, bool can_seek, bool can_read, bool can_write,
bool auto_close);
-
- CRU_DELETE_COPY(UnixFileStream)
- CRU_DELETE_MOVE(UnixFileStream)
-
~UnixFileStream() override;
public:
- bool CanSeek() override;
- Index Seek(Index offset, SeekOrigin origin = SeekOrigin::Current) override;
-
- bool CanRead() override;
- Index Read(std::byte* buffer, Index offset, Index size) override;
- using Stream::Read;
-
- bool CanWrite() override;
- Index Write(const std::byte* buffer, Index offset, Index size) override;
- using Stream::Write;
-
- void Close() override;
+ CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE
int GetFileDescriptor() const { return file_descriptor_; }
+ protected:
+ Index DoSeek(Index offset, SeekOrigin origin = SeekOrigin::Current) override;
+ Index DoRead(std::byte* buffer, Index offset, Index size) override;
+ Index DoWrite(const std::byte* buffer, Index offset, Index size) override;
+
private:
- void CheckClosed();
+ void DoClose();
private:
int file_descriptor_; // -1 for no file descriptor
- bool can_seek_;
- bool can_read_;
- bool can_write_;
bool auto_close_;
};
} // namespace cru::platform::unix