summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
Diffstat (limited to 'AK')
-rw-r--r--AK/BitStream.h44
-rw-r--r--AK/BufferedStream.h6
-rw-r--r--AK/MemoryStream.cpp10
-rw-r--r--AK/MemoryStream.h8
-rw-r--r--AK/Stream.cpp8
-rw-r--r--AK/Stream.h4
6 files changed, 44 insertions, 36 deletions
diff --git a/AK/BitStream.h b/AK/BitStream.h
index c5a3d89801..25dfb265d0 100644
--- a/AK/BitStream.h
+++ b/AK/BitStream.h
@@ -23,16 +23,17 @@ public:
}
// ^Stream
- virtual ErrorOr<Bytes> read(Bytes bytes) override
+ virtual ErrorOr<Bytes> read_some(Bytes bytes) override
{
if (m_current_byte.has_value() && is_aligned_to_byte_boundary()) {
bytes[0] = m_current_byte.release_value();
- return m_stream->read(bytes.slice(1));
+ // FIXME: This accidentally slices off the first byte of the returned span.
+ return m_stream->read_some(bytes.slice(1));
}
align_to_byte_boundary();
- return m_stream->read(bytes);
+ return m_stream->read_some(bytes);
}
- virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream->write(bytes); }
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_stream->write_some(bytes); }
virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes bytes) override { return m_stream->write_entire_buffer(bytes); }
virtual bool is_eof() const override { return m_stream->is_eof() && !m_current_byte.has_value(); }
virtual bool is_open() const override { return m_stream->is_open(); }
@@ -91,7 +92,9 @@ public:
}
} else {
auto temp_buffer = TRY(ByteBuffer::create_uninitialized(1));
- TRY(m_stream->read(temp_buffer.bytes()));
+ // FIXME: This should read the entire span.
+ // FIXME: This should just write into m_current_byte directly.
+ TRY(m_stream->read_some(temp_buffer.bytes()));
m_current_byte = temp_buffer[0];
m_bit_offset = 0;
}
@@ -127,16 +130,17 @@ public:
}
// ^Stream
- virtual ErrorOr<Bytes> read(Bytes bytes) override
+ virtual ErrorOr<Bytes> read_some(Bytes bytes) override
{
if (m_current_byte.has_value() && is_aligned_to_byte_boundary()) {
bytes[0] = m_current_byte.release_value();
- return m_stream->read(bytes.slice(1));
+ // FIXME: This accidentally slices off the first byte of the returned span.
+ return m_stream->read_some(bytes.slice(1));
}
align_to_byte_boundary();
- return m_stream->read(bytes);
+ return m_stream->read_some(bytes);
}
- virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_stream->write(bytes); }
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_stream->write_some(bytes); }
virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes bytes) override { return m_stream->write_entire_buffer(bytes); }
virtual bool is_eof() const override { return m_stream->is_eof() && !m_current_byte.has_value(); }
virtual bool is_open() const override { return m_stream->is_open(); }
@@ -191,7 +195,9 @@ public:
}
} else {
auto temp_buffer = TRY(ByteBuffer::create_uninitialized(1));
- auto read_bytes = TRY(m_stream->read(temp_buffer.bytes()));
+ // FIXME: This should read the entire span.
+ // FIXME: This should just write into m_current_byte directly.
+ auto read_bytes = TRY(m_stream->read_some(temp_buffer.bytes()));
if (read_bytes.is_empty())
return Error::from_string_literal("eof");
m_current_byte = temp_buffer[0];
@@ -230,15 +236,15 @@ public:
{
}
- virtual ErrorOr<Bytes> read(Bytes) override
+ virtual ErrorOr<Bytes> read_some(Bytes) override
{
return Error::from_errno(EBADF);
}
- virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override
{
VERIFY(m_bit_offset == 0);
- return m_stream->write(bytes);
+ return m_stream->write_some(bytes);
}
template<Unsigned T>
@@ -255,7 +261,8 @@ public:
m_bit_offset++;
if (m_bit_offset > 7) {
- TRY(m_stream->write({ &m_current_byte, sizeof(m_current_byte) }));
+ // FIXME: This should write the entire span.
+ TRY(m_stream->write_some({ &m_current_byte, sizeof(m_current_byte) }));
m_bit_offset = 0;
m_current_byte = 0;
}
@@ -308,15 +315,15 @@ public:
{
}
- virtual ErrorOr<Bytes> read(Bytes) override
+ virtual ErrorOr<Bytes> read_some(Bytes) override
{
return Error::from_errno(EBADF);
}
- virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override
{
VERIFY(m_bit_offset == 0);
- return m_stream->write(bytes);
+ return m_stream->write_some(bytes);
}
template<Unsigned T>
@@ -333,7 +340,8 @@ public:
m_bit_offset++;
if (m_bit_offset > 7) {
- TRY(m_stream->write({ &m_current_byte, sizeof(m_current_byte) }));
+ // FIXME: This should write the entire span.
+ TRY(m_stream->write_some({ &m_current_byte, sizeof(m_current_byte) }));
m_bit_offset = 0;
m_current_byte = 0;
}
diff --git a/AK/BufferedStream.h b/AK/BufferedStream.h
index b34868952f..4b454d15e9 100644
--- a/AK/BufferedStream.h
+++ b/AK/BufferedStream.h
@@ -236,7 +236,7 @@ private:
auto const fillable_slice = temporary_buffer.span().trim(min(temporary_buffer.size(), m_buffer.empty_space()));
size_t nread = 0;
do {
- auto result = stream().read(fillable_slice);
+ auto result = stream().read_some(fillable_slice);
if (result.is_error()) {
if (!result.error().is_errno())
return result.release_error();
@@ -274,8 +274,8 @@ public:
BufferedSeekable(BufferedSeekable&& other) = default;
BufferedSeekable& operator=(BufferedSeekable&& other) = default;
- virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(move(buffer)); }
- virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.stream().write(buffer); }
+ virtual ErrorOr<Bytes> read_some(Bytes buffer) override { return m_helper.read(move(buffer)); }
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes buffer) override { return m_helper.stream().write_some(buffer); }
virtual bool is_eof() const override { return m_helper.is_eof(); }
virtual bool is_open() const override { return m_helper.stream().is_open(); }
virtual void close() override { m_helper.stream().close(); }
diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp
index 237fd345bf..e1131b3cd8 100644
--- a/AK/MemoryStream.cpp
+++ b/AK/MemoryStream.cpp
@@ -43,7 +43,7 @@ ErrorOr<void> FixedMemoryStream::truncate(size_t)
return Error::from_errno(EBADF);
}
-ErrorOr<Bytes> FixedMemoryStream::read(Bytes bytes)
+ErrorOr<Bytes> FixedMemoryStream::read_some(Bytes bytes)
{
auto to_read = min(remaining(), bytes.size());
if (to_read == 0)
@@ -79,7 +79,7 @@ ErrorOr<size_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode)
return m_offset;
}
-ErrorOr<size_t> FixedMemoryStream::write(ReadonlyBytes bytes)
+ErrorOr<size_t> FixedMemoryStream::write_some(ReadonlyBytes bytes)
{
VERIFY(m_writing_enabled);
@@ -94,7 +94,7 @@ ErrorOr<void> FixedMemoryStream::write_entire_buffer(ReadonlyBytes bytes)
if (remaining() < bytes.size())
return Error::from_string_view_or_print_error_and_return_errno("Write of entire buffer ends past the memory area"sv, EINVAL);
- TRY(write(bytes));
+ TRY(write_some(bytes));
return {};
}
@@ -118,7 +118,7 @@ size_t FixedMemoryStream::remaining() const
return m_bytes.size() - m_offset;
}
-ErrorOr<Bytes> AllocatingMemoryStream::read(Bytes bytes)
+ErrorOr<Bytes> AllocatingMemoryStream::read_some(Bytes bytes)
{
size_t read_bytes = 0;
@@ -140,7 +140,7 @@ ErrorOr<Bytes> AllocatingMemoryStream::read(Bytes bytes)
return bytes.trim(read_bytes);
}
-ErrorOr<size_t> AllocatingMemoryStream::write(ReadonlyBytes bytes)
+ErrorOr<size_t> AllocatingMemoryStream::write_some(ReadonlyBytes bytes)
{
size_t written_bytes = 0;
diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h
index fa4961b77b..c1fe27a27c 100644
--- a/AK/MemoryStream.h
+++ b/AK/MemoryStream.h
@@ -23,11 +23,11 @@ public:
virtual bool is_open() const override;
virtual void close() override;
virtual ErrorOr<void> truncate(size_t) override;
- virtual ErrorOr<Bytes> read(Bytes bytes) override;
+ virtual ErrorOr<Bytes> read_some(Bytes bytes) override;
virtual ErrorOr<size_t> seek(i64 offset, SeekMode seek_mode = SeekMode::SetPosition) override;
- virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override;
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override;
virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes bytes) override;
Bytes bytes();
@@ -45,8 +45,8 @@ private:
/// and reading back the written data afterwards.
class AllocatingMemoryStream final : public Stream {
public:
- virtual ErrorOr<Bytes> read(Bytes) override;
- virtual ErrorOr<size_t> write(ReadonlyBytes) override;
+ virtual ErrorOr<Bytes> read_some(Bytes) override;
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
virtual ErrorOr<void> discard(size_t) override;
virtual bool is_eof() const override;
virtual bool is_open() const override;
diff --git a/AK/Stream.cpp b/AK/Stream.cpp
index c47afe3dbf..ab0c572391 100644
--- a/AK/Stream.cpp
+++ b/AK/Stream.cpp
@@ -18,7 +18,7 @@ ErrorOr<void> Stream::read_entire_buffer(Bytes buffer)
if (is_eof())
return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before filling the entire buffer"sv, EIO);
- auto result = read(buffer.slice(nread));
+ auto result = read_some(buffer.slice(nread));
if (result.is_error()) {
if (result.error().is_errno() && result.error().code() == EINTR) {
continue;
@@ -50,7 +50,7 @@ ErrorOr<ByteBuffer> Stream::read_until_eof_impl(size_t block_size, size_t expect
buffer = TRY(data.get_bytes_for_writing(block_size));
}
- auto nread = TRY(read(buffer)).size();
+ auto nread = TRY(read_some(buffer)).size();
total_read += nread;
buffer = buffer.slice(nread);
}
@@ -71,7 +71,7 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
if (is_eof())
return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before reading all discarded bytes"sv, EIO);
- auto slice = TRY(read(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
+ auto slice = TRY(read_some(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
discarded_bytes -= slice.size();
}
@@ -82,7 +82,7 @@ ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer)
{
size_t nwritten = 0;
while (nwritten < buffer.size()) {
- auto result = write(buffer.slice(nwritten));
+ auto result = write_some(buffer.slice(nwritten));
if (result.is_error()) {
if (result.error().is_errno() && result.error().code() == EINTR) {
continue;
diff --git a/AK/Stream.h b/AK/Stream.h
index d01ae9ddb3..8211cf8687 100644
--- a/AK/Stream.h
+++ b/AK/Stream.h
@@ -23,7 +23,7 @@ public:
/// The amount of bytes read can be smaller than the size of the buffer.
/// Returns either the bytes that were read, or an errno in the case of
/// failure.
- virtual ErrorOr<Bytes> read(Bytes) = 0;
+ virtual ErrorOr<Bytes> read_some(Bytes) = 0;
/// Tries to fill the entire buffer through reading. Returns whether the
/// buffer was filled without an error.
virtual ErrorOr<void> read_entire_buffer(Bytes);
@@ -41,7 +41,7 @@ public:
/// Tries to write the entire contents of the buffer. It is possible for
/// less than the full buffer to be written. Returns either the amount of
/// bytes written into the stream, or an errno in the case of failure.
- virtual ErrorOr<size_t> write(ReadonlyBytes) = 0;
+ virtual ErrorOr<size_t> write_some(ReadonlyBytes) = 0;
/// Same as write, but does not return until either the entire buffer
/// contents are written or an error occurs.
virtual ErrorOr<void> write_entire_buffer(ReadonlyBytes);