AK: Rename Stream::{read,write} to Stream::{read_some,write_some}

Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
This commit is contained in:
Tim Schumacher 2023-02-24 22:38:01 +01:00 committed by Linus Groh
parent 1d5b45f7d9
commit d5871f5717
Notes: sideshowbarker 2024-07-17 06:40:21 +09:00
109 changed files with 474 additions and 329 deletions

View file

@ -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;
}

View file

@ -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(); }

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -211,7 +211,8 @@ namespace PnpIDs {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -265,7 +266,8 @@ IterationDecision for_each(Function<IterationDecision(PnpIDData const&)> callbac
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -405,7 +405,8 @@ ErrorOr<void> generate_header_file(JsonObject& api_data, Core::File& file)
generator.appendln("}");
generator.appendln("#endif");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -529,7 +530,8 @@ ErrorOr<void> generate_implementation_file(JsonObject& api_data, Core::File& fil
}
});
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -1724,7 +1724,8 @@ namespace Locale {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -2397,7 +2398,8 @@ Optional<StringView> get_time_zone_name(StringView locale, StringView time_zone,
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -1047,7 +1047,8 @@ namespace Locale {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -1747,7 +1748,8 @@ ErrorOr<Optional<String>> resolve_most_likely_territory(LanguageID const& langua
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -763,7 +763,8 @@ namespace Locale {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -1107,7 +1108,8 @@ ErrorOr<Vector<NumberFormat>> get_unit_formats(StringView locale, StringView uni
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -442,7 +442,8 @@ namespace Locale {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -654,7 +655,8 @@ PluralCategory determine_plural_range(StringView locale, PluralCategory start, P
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -180,7 +180,8 @@ namespace Locale {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -276,7 +277,8 @@ ErrorOr<Vector<RelativeTimeFormat>> get_relative_time_format_patterns(StringView
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -469,7 +469,8 @@ namespace TimeZone {
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -801,7 +802,8 @@ Vector<StringView> time_zones_in_region(StringView region)
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -213,7 +213,8 @@ static ErrorOr<void> generate_emoji_data_header(Core::BufferedFile& file, EmojiD
StringBuilder builder;
SourceGenerator generator { builder };
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -334,7 +335,8 @@ Optional<Emoji> find_emoji_for_code_points(ReadonlySpan<u32> code_points)
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -379,7 +381,8 @@ static ErrorOr<void> generate_emoji_installation(Core::BufferedFile& file, Emoji
generator.append(" @name@ (@status@)\n"sv);
}
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -866,7 +866,8 @@ ReadonlySpan<CaseFolding const*> case_folding_mapping(u32 code_point);
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -1354,7 +1355,8 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -160,7 +160,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (global_mixin_implementation_mode)
IDL::generate_global_mixin_implementation(interface, output_builder);
TRY(output_file->write(output_builder.string_view().bytes()));
// FIXME: This should write the entire span.
TRY(output_file->write_some(output_builder.string_view().bytes()));
if (!depfile_path.is_null()) {
auto depfile = TRY(Core::File::open_file_or_standard_stream(depfile_path, Core::File::OpenMode::Write));
@ -173,7 +174,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
depfile_builder.append(path);
}
depfile_builder.append('\n');
TRY(depfile->write(depfile_builder.string_view().bytes()));
// FIXME: This should write the entire span.
TRY(depfile->write_some(depfile_builder.string_view().bytes()));
}
return 0;
}

View file

@ -95,7 +95,8 @@ enum class ValueID;
generator.appendln("}");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -199,6 +200,7 @@ StringView to_string(@name:titlecase@ value)
generator.appendln("}");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -80,7 +80,8 @@ bool media_feature_accepts_identifier(MediaFeatureID, ValueID);
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -290,6 +291,7 @@ bool media_feature_accepts_identifier(MediaFeatureID media_feature_id, ValueID i
}
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -140,7 +140,8 @@ struct Traits<Web::CSS::PropertyID> : public GenericTraits<Web::CSS::PropertyID>
} // namespace AK
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -605,6 +606,7 @@ size_t property_maximum_value_count(PropertyID property_id)
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -96,7 +96,8 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction);
generator.appendln("\n}");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -205,6 +206,7 @@ TransformFunctionMetadata transform_function_metadata(TransformFunction transfor
generator.appendln("\n}");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -74,7 +74,8 @@ StringView string_from_value_id(ValueID);
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}
@ -134,6 +135,7 @@ StringView string_from_value_id(ValueID value_id) {
} // namespace Web::CSS
)~~~");
TRY(file.write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -105,7 +105,8 @@ class @legacy_constructor_class@;)~~~");
auto generated_forward_path = LexicalPath(output_path).append("Forward.h"sv).string();
auto generated_forward_file = TRY(Core::File::open(generated_forward_path, Core::File::OpenMode::Write));
TRY(generated_forward_file->write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(generated_forward_file->write_some(generator.as_string_view().bytes()));
return {};
}
@ -208,7 +209,8 @@ void Intrinsics::create_web_prototype_and_constructor<@prototype_class@>(JS::Rea
auto generated_intrinsics_path = LexicalPath(output_path).append("IntrinsicDefinitions.cpp"sv).string();
auto generated_intrinsics_file = TRY(Core::File::open(generated_intrinsics_path, Core::File::OpenMode::Write));
TRY(generated_intrinsics_file->write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(generated_intrinsics_file->write_some(generator.as_string_view().bytes()));
return {};
}
@ -234,7 +236,8 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object&);
auto generated_header_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.h", class_name)).string();
auto generated_header_file = TRY(Core::File::open(generated_header_path, Core::File::OpenMode::Write));
TRY(generated_header_file->write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(generated_header_file->write_some(generator.as_string_view().bytes()));
return {};
}
@ -303,7 +306,8 @@ void add_@global_object_snake_name@_exposed_interfaces(JS::Object& global)
auto generated_implementation_path = LexicalPath(output_path).append(DeprecatedString::formatted("{}ExposedInterfaces.cpp", class_name)).string();
auto generated_implementation_file = TRY(Core::File::open(generated_implementation_path, Core::File::OpenMode::Write));
TRY(generated_implementation_file->write(generator.as_string_view().bytes()));
// FIXME: This should write the entire span.
TRY(generated_implementation_file->write_some(generator.as_string_view().bytes()));
return {};
}

View file

@ -63,8 +63,8 @@ void displayln(CheckedFormatString<Args...> format_string, Args const&... args)
void displayln() { user_display("\n", 1); }
class UserDisplayStream final : public Stream {
virtual ErrorOr<Bytes> read(Bytes) override { return Error::from_string_view("Not readable"sv); };
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override
virtual ErrorOr<Bytes> read_some(Bytes) override { return Error::from_string_view("Not readable"sv); };
virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override
{
user_display(bit_cast<char const*>(bytes.data()), bytes.size());
return bytes.size();

View file

@ -16,7 +16,7 @@ TEST_CASE(allocating_memory_stream_empty)
{
Array<u8, 32> array;
auto read_bytes = MUST(stream.read(array));
auto read_bytes = MUST(stream.read_some(array));
EXPECT_EQ(read_bytes.size(), 0ul);
}

View file

@ -98,7 +98,8 @@ TEST_CASE(long_streams)
u8 bytes[64] = {};
constexpr auto test_view = "Well, hello friends"sv;
FixedMemoryStream stream(Bytes { bytes, sizeof(bytes) });
MUST(stream.write(test_view.bytes()));
// FIXME: This should write the entire span.
MUST(stream.write_some(test_view.bytes()));
MUST(stream.seek(0));
auto string = MUST(String::from_stream(stream, test_view.length()));
@ -110,7 +111,8 @@ TEST_CASE(long_streams)
{
AllocatingMemoryStream stream;
MUST(stream.write(("abc"sv).bytes()));
// FIXME: This should write the entire span.
MUST(stream.write_some(("abc"sv).bytes()));
auto string = MUST(String::from_stream(stream, 3u));
@ -121,7 +123,8 @@ TEST_CASE(long_streams)
{
AllocatingMemoryStream stream;
MUST(stream.write(("0123456789"sv).bytes()));
// FIXME: This should write the entire span.
MUST(stream.write_some(("0123456789"sv).bytes()));
auto string = MUST(String::from_stream(stream, 9u));

View file

@ -104,7 +104,7 @@ TEST_CASE(brotli_decompress_zero_one_bin)
size_t bytes_read = 0;
while (true) {
size_t nread = MUST(brotli_stream.read(buffer)).size();
size_t nread = MUST(brotli_stream.read_some(buffer)).size();
if (nread == 0)
break;

View file

@ -46,7 +46,7 @@ TEST_CASE(file_write_bytes)
constexpr auto some_words = "These are some words"sv;
ReadonlyBytes buffer { some_words.characters_without_null_termination(), some_words.length() };
auto result = file->write(buffer);
auto result = file->write_some(buffer);
EXPECT(!result.is_error());
}
@ -62,7 +62,7 @@ TEST_CASE(file_read_bytes)
EXPECT(!maybe_buffer.is_error());
auto buffer = maybe_buffer.release_value();
auto result = file->read(buffer);
auto result = file->read_some(buffer);
EXPECT(!result.is_error());
EXPECT_EQ(result.value().size(), 131ul);
@ -185,7 +185,7 @@ TEST_CASE(tcp_socket_read)
auto maybe_server_socket = tcp_server->accept();
EXPECT(!maybe_server_socket.is_error());
auto server_socket = maybe_server_socket.release_value();
EXPECT(!server_socket->write({ sent_data.characters_without_null_termination(), sent_data.length() }).is_error());
EXPECT(!server_socket->write_some({ sent_data.characters_without_null_termination(), sent_data.length() }).is_error());
server_socket->close();
EXPECT(client_socket->can_read_without_blocking(100).release_value());
@ -194,7 +194,7 @@ TEST_CASE(tcp_socket_read)
auto maybe_receive_buffer = ByteBuffer::create_uninitialized(64);
EXPECT(!maybe_receive_buffer.is_error());
auto receive_buffer = maybe_receive_buffer.release_value();
auto maybe_read_bytes = client_socket->read(receive_buffer);
auto maybe_read_bytes = client_socket->read_some(receive_buffer);
EXPECT(!maybe_read_bytes.is_error());
auto read_bytes = maybe_read_bytes.release_value();
@ -227,7 +227,7 @@ TEST_CASE(tcp_socket_write)
auto maybe_receive_buffer = ByteBuffer::create_uninitialized(64);
EXPECT(!maybe_receive_buffer.is_error());
auto receive_buffer = maybe_receive_buffer.release_value();
auto maybe_read_bytes = server_socket->read(receive_buffer);
auto maybe_read_bytes = server_socket->read_some(receive_buffer);
EXPECT(!maybe_read_bytes.is_error());
auto read_bytes = maybe_read_bytes.release_value();
@ -263,7 +263,7 @@ TEST_CASE(tcp_socket_eof)
auto maybe_receive_buffer = ByteBuffer::create_uninitialized(1);
EXPECT(!maybe_receive_buffer.is_error());
auto receive_buffer = maybe_receive_buffer.release_value();
EXPECT(client_socket->read(receive_buffer).release_value().is_empty());
EXPECT(client_socket->read_some(receive_buffer).release_value().is_empty());
EXPECT(client_socket->is_eof());
}
@ -307,12 +307,12 @@ TEST_CASE(udp_socket_read_write)
// Testing that supplying a smaller buffer than required causes a failure.
auto small_buffer = ByteBuffer::create_uninitialized(8).release_value();
EXPECT_EQ(client_socket->read(small_buffer).error().code(), EMSGSIZE);
EXPECT_EQ(client_socket->read_some(small_buffer).error().code(), EMSGSIZE);
auto maybe_client_receive_buffer = ByteBuffer::create_uninitialized(64);
EXPECT(!maybe_client_receive_buffer.is_error());
auto client_receive_buffer = maybe_client_receive_buffer.release_value();
auto maybe_read_bytes = client_socket->read(client_receive_buffer);
auto maybe_read_bytes = client_socket->read_some(client_receive_buffer);
EXPECT(!maybe_read_bytes.is_error());
auto read_bytes = maybe_read_bytes.release_value();
@ -330,7 +330,7 @@ TEST_CASE(local_socket_read)
EXPECT(local_server->listen("/tmp/test-socket"));
local_server->on_accept = [&](NonnullOwnPtr<Core::LocalSocket> server_socket) {
EXPECT(!server_socket->write(sent_data.bytes()).is_error());
EXPECT(!server_socket->write_some(sent_data.bytes()).is_error());
event_loop.quit(0);
event_loop.pump();
@ -356,7 +356,7 @@ TEST_CASE(local_socket_read)
auto maybe_receive_buffer = ByteBuffer::create_uninitialized(64);
EXPECT(!maybe_receive_buffer.is_error());
auto receive_buffer = maybe_receive_buffer.release_value();
auto maybe_read_bytes = client_socket->read(receive_buffer);
auto maybe_read_bytes = client_socket->read_some(receive_buffer);
EXPECT(!maybe_read_bytes.is_error());
auto read_bytes = maybe_read_bytes.release_value();
@ -387,7 +387,7 @@ TEST_CASE(local_socket_write)
auto maybe_receive_buffer = ByteBuffer::create_uninitialized(pending_bytes);
EXPECT(!maybe_receive_buffer.is_error());
auto receive_buffer = maybe_receive_buffer.release_value();
auto maybe_read_bytes = server_socket->read(receive_buffer);
auto maybe_read_bytes = server_socket->read_some(receive_buffer);
EXPECT(!maybe_read_bytes.is_error());
EXPECT_EQ(maybe_read_bytes.value().size(), sent_data.length());
@ -578,7 +578,7 @@ TEST_CASE(buffered_tcp_socket_read)
auto maybe_server_socket = tcp_server->accept();
EXPECT(!maybe_server_socket.is_error());
auto server_socket = maybe_server_socket.release_value();
EXPECT(!server_socket->write({ buffered_sent_data.characters_without_null_termination(), sent_data.length() }).is_error());
EXPECT(!server_socket->write_some({ buffered_sent_data.characters_without_null_termination(), sent_data.length() }).is_error());
EXPECT(client_socket->can_read_without_blocking(100).release_value());

View file

@ -88,7 +88,7 @@ TEST_CASE(test_TLS_hello_handshake)
auto tls = MUST(TLS::TLSv12::connect(DEFAULT_SERVER, port, move(options)));
ByteBuffer contents;
tls->on_ready_to_read = [&] {
auto read_bytes = MUST(tls->read(contents.must_get_bytes_for_writing(4 * KiB)));
auto read_bytes = MUST(tls->read_some(contents.must_get_bytes_for_writing(4 * KiB)));
if (read_bytes.is_empty()) {
FAIL("No data received");
loop.quit(1);

View file

@ -32,7 +32,8 @@ TESTJS_GLOBAL_FUNCTION(read_binary_wasm_file, readBinaryWasmFile)
auto array = TRY(JS::Uint8Array::create(realm, file_size.value()));
auto read = file.value()->read(array->data());
// FIXME: This should read the entire span.
auto read = file.value()->read_some(array->data());
if (read.is_error())
return vm.throw_completion<JS::TypeError>(error_code_to_string(read.error().code()));

View file

@ -211,7 +211,8 @@ TEST_CASE(regression)
auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read));
auto file_size = MUST(file->size());
auto content = MUST(ByteBuffer::create_uninitialized(file_size));
MUST(file->read(content.bytes()));
// FIXME: This should read the entire span.
MUST(file->read_some(content.bytes()));
DeprecatedString file_contents { content.bytes() };
auto tokens = run_tokenizer(file_contents);
u32 hash = hash_tokens(tokens);

View file

@ -775,7 +775,8 @@ ErrorOr<void> BrowserWindow::take_screenshot(ScreenshotType type)
auto encoded = TRY(Gfx::PNGWriter::encode(*bitmap.bitmap()));
auto screenshot_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write));
TRY(screenshot_file->write(encoded));
// FIXME: This should write the entire span.
TRY(screenshot_file->write_some(encoded));
return {};
}

View file

@ -50,7 +50,8 @@ ErrorOr<void> DomainListModel::save()
TRY(builder.try_appendff("{}\n", domain));
auto file = TRY(Core::File::open(filter_list_file_path(), Core::File::OpenMode::Write));
TRY(file->write(TRY(builder.to_byte_buffer()).bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(TRY(builder.to_byte_buffer()).bytes()));
return {};
}

View file

@ -284,7 +284,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
auto byte_buffer = byte_buffer_or_error.release_value();
if (auto result = file->write(byte_buffer); result.is_error())
// FIXME: This should write the entire span.
if (auto result = file->write_some(byte_buffer); result.is_error())
GUI::MessageBox::show(window, DeprecatedString::formatted("Couldn't save file: {}.", result.release_error()), "Saving backtrace failed"sv, GUI::MessageBox::Type::Error);
};
save_backtrace_button.set_enabled(false);

View file

@ -62,10 +62,12 @@ void HexDocumentMemory::clear_changes()
ErrorOr<void> HexDocumentMemory::write_to_file(Core::File& file)
{
TRY(file.seek(0, SeekMode::SetPosition));
TRY(file.write(m_buffer));
// FIXME: This should write the entire span.
TRY(file.write_some(m_buffer));
for (auto& change : m_changes) {
TRY(file.seek(change.key, SeekMode::SetPosition));
TRY(file.write({ &change.value, 1 }));
// FIXME: This should write the entire span.
TRY(file.write_some({ &change.value, 1 }));
}
return {};
}
@ -87,7 +89,8 @@ ErrorOr<void> HexDocumentFile::write_to_file()
{
for (auto& change : m_changes) {
TRY(m_file->seek(change.key, SeekMode::SetPosition));
TRY(m_file->write({ &change.value, 1 }));
// FIXME: This should write the entire span.
TRY(m_file->write_some({ &change.value, 1 }));
}
clear_changes();
// make sure the next get operation triggers a read
@ -104,15 +107,17 @@ ErrorOr<void> HexDocumentFile::write_to_file(Core::File& file)
while (true) {
Array<u8, 64 * KiB> buffer;
auto copy_buffer = TRY(m_file->read(buffer));
auto copy_buffer = TRY(m_file->read_some(buffer));
if (copy_buffer.size() == 0)
break;
TRY(file.write(copy_buffer));
// FIXME: This should write the entire span.
TRY(file.write_some(copy_buffer));
}
for (auto& change : m_changes) {
TRY(file.seek(change.key, SeekMode::SetPosition));
TRY(file.write({ &change.value, 1 }));
// FIXME: This should write the entire span.
TRY(file.write_some({ &change.value, 1 }));
}
return {};
@ -181,7 +186,8 @@ void HexDocumentFile::ensure_position_in_buffer(size_t position)
{
if (position < m_buffer_file_pos || position >= m_buffer_file_pos + m_buffer.size()) {
m_file->seek(position, SeekMode::SetPosition).release_value_but_fixme_should_propagate_errors();
m_file->read(m_buffer).release_value_but_fixme_should_propagate_errors();
// FIXME: This seems wrong. We don't track how much of the buffer is actually filled.
m_file->read_some(m_buffer).release_value_but_fixme_should_propagate_errors();
m_buffer_file_pos = position;
}
}

View file

@ -191,7 +191,8 @@ ErrorOr<void> KeyboardMapperWidget::save_to_file(StringView filename)
// Write to file.
DeprecatedString file_content = map_json.to_deprecated_string();
auto file = TRY(Core::File::open(filename, Core::File::OpenMode::Write));
TRY(file->write(file_content.bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(file_content.bytes()));
file->close();
window()->set_modified(false);

View file

@ -73,7 +73,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
filename = path.basename();
auto encoded = TRY(dump_bitmap(magnifier->current_bitmap(), path.extension()));
TRY(file->write(encoded));
// FIXME: This should write the entire span.
TRY(file->write_some(encoded));
return {};
};

View file

@ -187,7 +187,8 @@ ErrorOr<void> RunWindow::save_history()
// Write the first 25 items of history
for (int i = 0; i < min(static_cast<int>(m_path_history.size()), 25); i++)
TRY(file->write(DeprecatedString::formatted("{}\n", m_path_history[i]).bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(DeprecatedString::formatted("{}\n", m_path_history[i]).bytes()));
return {};
}

View file

@ -632,24 +632,25 @@ ErrorOr<void> ChessWidget::import_pgn(Core::File& file)
ErrorOr<void> ChessWidget::export_pgn(Core::File& file) const
{
// Tag Pair Section
TRY(file.write("[Event \"Casual Game\"]\n"sv.bytes()));
TRY(file.write("[Site \"SerenityOS Chess\"]\n"sv.bytes()));
TRY(file.write(DeprecatedString::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_deprecated_string("%Y.%m.%d"sv)).bytes()));
TRY(file.write("[Round \"1\"]\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some("[Event \"Casual Game\"]\n"sv.bytes()));
TRY(file.write_some("[Site \"SerenityOS Chess\"]\n"sv.bytes()));
TRY(file.write_some(DeprecatedString::formatted("[Date \"{}\"]\n", Core::DateTime::now().to_deprecated_string("%Y.%m.%d"sv)).bytes()));
TRY(file.write_some("[Round \"1\"]\n"sv.bytes()));
DeprecatedString username(getlogin());
auto const player1 = (!username.is_empty() ? username.view() : "?"sv.bytes());
auto const player2 = (!m_engine.is_null() ? "SerenityOS ChessEngine"sv.bytes() : "?"sv.bytes());
TRY(file.write(DeprecatedString::formatted("[White \"{}\"]\n", m_side == Chess::Color::White ? player1 : player2).bytes()));
TRY(file.write(DeprecatedString::formatted("[Black \"{}\"]\n", m_side == Chess::Color::Black ? player1 : player2).bytes()));
TRY(file.write_some(DeprecatedString::formatted("[White \"{}\"]\n", m_side == Chess::Color::White ? player1 : player2).bytes()));
TRY(file.write_some(DeprecatedString::formatted("[Black \"{}\"]\n", m_side == Chess::Color::Black ? player1 : player2).bytes()));
TRY(file.write(DeprecatedString::formatted("[Result \"{}\"]\n", Chess::Board::result_to_points_string(m_board.game_result(), m_board.turn())).bytes()));
TRY(file.write("[WhiteElo \"?\"]\n"sv.bytes()));
TRY(file.write("[BlackElo \"?\"]\n"sv.bytes()));
TRY(file.write("[Variant \"Standard\"]\n"sv.bytes()));
TRY(file.write("[TimeControl \"-\"]\n"sv.bytes()));
TRY(file.write("[Annotator \"SerenityOS Chess\"]\n"sv.bytes()));
TRY(file.write("\n"sv.bytes()));
TRY(file.write_some(DeprecatedString::formatted("[Result \"{}\"]\n", Chess::Board::result_to_points_string(m_board.game_result(), m_board.turn())).bytes()));
TRY(file.write_some("[WhiteElo \"?\"]\n"sv.bytes()));
TRY(file.write_some("[BlackElo \"?\"]\n"sv.bytes()));
TRY(file.write_some("[Variant \"Standard\"]\n"sv.bytes()));
TRY(file.write_some("[TimeControl \"-\"]\n"sv.bytes()));
TRY(file.write_some("[Annotator \"SerenityOS Chess\"]\n"sv.bytes()));
TRY(file.write_some("\n"sv.bytes()));
// Movetext Section
for (size_t i = 0, move_no = 1; i < m_board.moves().size(); i += 2, move_no++) {
@ -657,17 +658,17 @@ ErrorOr<void> ChessWidget::export_pgn(Core::File& file) const
if (i + 1 < m_board.moves().size()) {
const DeprecatedString black = m_board.moves().at(i + 1).to_algebraic();
TRY(file.write(DeprecatedString::formatted("{}. {} {} ", move_no, white, black).bytes()));
TRY(file.write_some(DeprecatedString::formatted("{}. {} {} ", move_no, white, black).bytes()));
} else {
TRY(file.write(DeprecatedString::formatted("{}. {} ", move_no, white).bytes()));
TRY(file.write_some(DeprecatedString::formatted("{}. {} ", move_no, white).bytes()));
}
}
TRY(file.write("{ "sv.bytes()));
TRY(file.write(Chess::Board::result_to_string(m_board.game_result(), m_board.turn()).bytes()));
TRY(file.write(" } "sv.bytes()));
TRY(file.write(Chess::Board::result_to_points_string(m_board.game_result(), m_board.turn()).bytes()));
TRY(file.write("\n"sv.bytes()));
TRY(file.write_some("{ "sv.bytes()));
TRY(file.write_some(Chess::Board::result_to_string(m_board.game_result(), m_board.turn()).bytes()));
TRY(file.write_some(" } "sv.bytes()));
TRY(file.write_some(Chess::Board::result_to_points_string(m_board.game_result(), m_board.turn()).bytes()));
TRY(file.write_some("\n"sv.bytes()));
return {};
}

View file

@ -18,7 +18,7 @@ TarFileStream::TarFileStream(TarInputStream& tar_stream)
{
}
ErrorOr<Bytes> TarFileStream::read(Bytes bytes)
ErrorOr<Bytes> TarFileStream::read_some(Bytes bytes)
{
// Verify that the stream has not advanced.
VERIFY(m_tar_stream.m_generation == m_generation);
@ -27,7 +27,7 @@ ErrorOr<Bytes> TarFileStream::read(Bytes bytes)
auto to_read = min(bytes.size(), header_size - m_tar_stream.m_file_offset);
auto slice = TRY(m_tar_stream.m_stream->read(bytes.trim(to_read)));
auto slice = TRY(m_tar_stream.m_stream->read_some(bytes.trim(to_read)));
m_tar_stream.m_file_offset += slice.size();
return slice;
@ -47,7 +47,7 @@ bool TarFileStream::is_eof() const
|| m_tar_stream.m_file_offset >= header_size;
}
ErrorOr<size_t> TarFileStream::write(ReadonlyBytes)
ErrorOr<size_t> TarFileStream::write_some(ReadonlyBytes)
{
return Error::from_errno(EBADF);
}
@ -92,7 +92,8 @@ ErrorOr<void> TarInputStream::load_next_header()
{
size_t number_of_consecutive_zero_blocks = 0;
while (true) {
auto header_span = TRY(m_stream->read(Bytes(&m_header, sizeof(m_header))));
// FIXME: This should read the entire span.
auto header_span = TRY(m_stream->read_some(Bytes(&m_header, sizeof(m_header))));
if (header_span.size() != sizeof(m_header))
return Error::from_string_literal("Failed to read the entire header");
@ -175,7 +176,7 @@ ErrorOr<void> TarOutputStream::add_file(StringView path, mode_t mode, ReadonlyBy
TRY(m_stream->write_entire_buffer(ReadonlyBytes { &padding, block_size - sizeof(header) }));
size_t n_written = 0;
while (n_written < bytes.size()) {
n_written += MUST(m_stream->write(bytes.slice(n_written, min(bytes.size() - n_written, block_size))));
n_written += MUST(m_stream->write_some(bytes.slice(n_written, min(bytes.size() - n_written, block_size))));
}
TRY(m_stream->write_entire_buffer(ReadonlyBytes { &padding, block_size - (n_written % block_size) }));
return {};

View file

@ -18,8 +18,8 @@ class TarInputStream;
class TarFileStream : 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 bool is_eof() const override;
virtual bool is_open() const override { return true; };
virtual void close() override {};

View file

@ -111,7 +111,8 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
// Parse checksum into a buffer first
[[maybe_unused]] u128 md5_checksum;
VERIFY(streaminfo_data.is_aligned_to_byte_boundary());
auto md5_bytes_read = LOADER_TRY(streaminfo_data.read(md5_checksum.bytes()));
// FIXME: This should read the entire span.
auto md5_bytes_read = LOADER_TRY(streaminfo_data.read_some(md5_checksum.bytes()));
FLAC_VERIFY(md5_bytes_read.size() == sizeof(md5_checksum), LoaderError::Category::IO, "MD5 Checksum size");
md5_checksum.bytes().copy_to({ m_md5_checksum, sizeof(m_md5_checksum) });
@ -228,7 +229,7 @@ ErrorOr<FlacRawMetadataBlock, LoaderError> FlacLoaderPlugin::next_meta_block(Big
// Blocks might exceed our buffer size.
auto bytes_left_to_read = block_data.bytes();
while (bytes_left_to_read.size()) {
auto read_bytes = LOADER_TRY(bit_input.read(bytes_left_to_read));
auto read_bytes = LOADER_TRY(bit_input.read_some(bytes_left_to_read));
bytes_left_to_read = bytes_left_to_read.slice(read_bytes.size());
}
@ -870,7 +871,8 @@ ErrorOr<u64> read_utf8_char(BigEndianInputBitStream& input)
u64 character;
u8 buffer = 0;
Bytes buffer_bytes { &buffer, 1 };
TRY(input.read(buffer_bytes));
// FIXME: This should read the entire span.
TRY(input.read_some(buffer_bytes));
u8 start_byte = buffer_bytes[0];
// Signal byte is zero: ASCII character
if ((start_byte & 0b10000000) == 0) {
@ -886,7 +888,8 @@ ErrorOr<u64> read_utf8_char(BigEndianInputBitStream& input)
u8 start_byte_bitmask = AK::exp2(bits_from_start_byte) - 1;
character = start_byte_bitmask & start_byte;
for (u8 i = length - 1; i > 0; --i) {
TRY(input.read(buffer_bytes));
// FIXME: This should read the entire span.
TRY(input.read_some(buffer_bytes));
u8 current_byte = buffer_bytes[0];
character = (character << 6) | (current_byte & 0b00111111);
}

View file

@ -233,7 +233,8 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header
size_t old_reservoir_size = m_bit_reservoir.used_buffer_size();
LOADER_TRY(m_bitstream->read_entire_buffer(buffer));
if (LOADER_TRY(m_bit_reservoir.write(buffer)) != header.slot_count)
// FIXME: This should write the entire span.
if (LOADER_TRY(m_bit_reservoir.write_some(buffer)) != header.slot_count)
return LoaderError { LoaderError::Category::IO, m_loaded_samples, "Could not write frame into bit reservoir." };
// If we don't have enough data in the reservoir to process this frame, skip it (but keep the data).

View file

@ -573,7 +573,7 @@ size_t BrotliDecompressionStream::literal_code_index_from_context()
return literal_code_index;
}
ErrorOr<Bytes> BrotliDecompressionStream::read(Bytes output_buffer)
ErrorOr<Bytes> BrotliDecompressionStream::read_some(Bytes output_buffer)
{
size_t bytes_read = 0;
while (bytes_read < output_buffer.size()) {
@ -653,7 +653,7 @@ ErrorOr<Bytes> BrotliDecompressionStream::read(Bytes output_buffer)
Bytes temp_bytes { temp_buffer, 4096 };
while (skip_length > 0) {
Bytes temp_bytes_slice = temp_bytes.slice(0, min(4096, skip_length));
auto metadata_bytes = TRY(m_input_stream.read(temp_bytes_slice));
auto metadata_bytes = TRY(m_input_stream.read_some(temp_bytes_slice));
if (metadata_bytes.is_empty())
return Error::from_string_literal("eof");
if (metadata_bytes.last() == 0)
@ -741,7 +741,7 @@ ErrorOr<Bytes> BrotliDecompressionStream::read(Bytes output_buffer)
size_t number_of_fitting_bytes = min(output_buffer.size() - bytes_read, m_bytes_left);
VERIFY(number_of_fitting_bytes > 0);
auto uncompressed_bytes = TRY(m_input_stream.read(output_buffer.slice(bytes_read, number_of_fitting_bytes)));
auto uncompressed_bytes = TRY(m_input_stream.read_some(output_buffer.slice(bytes_read, number_of_fitting_bytes)));
if (uncompressed_bytes.is_empty())
return Error::from_string_literal("eof");

View file

@ -104,8 +104,8 @@ public:
public:
BrotliDecompressionStream(Stream&);
ErrorOr<Bytes> read(Bytes output_buffer) override;
ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_input_stream.write(bytes); }
ErrorOr<Bytes> read_some(Bytes output_buffer) override;
ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_input_stream.write_some(bytes); }
bool is_eof() const override;
bool is_open() const override { return m_input_stream.is_open(); }
void close() override { m_input_stream.close(); }

View file

@ -181,7 +181,7 @@ ErrorOr<bool> DeflateDecompressor::UncompressedBlock::try_read_more()
Array<u8, 4096> temporary_buffer;
auto readable_bytes = temporary_buffer.span().trim(min(m_bytes_remaining, m_decompressor.m_output_buffer.empty_space()));
auto read_bytes = TRY(m_decompressor.m_input_stream->read(readable_bytes));
auto read_bytes = TRY(m_decompressor.m_input_stream->read_some(readable_bytes));
auto written_bytes = m_decompressor.m_output_buffer.write(read_bytes);
VERIFY(read_bytes.size() == written_bytes);
@ -209,7 +209,7 @@ DeflateDecompressor::~DeflateDecompressor()
m_uncompressed_block.~UncompressedBlock();
}
ErrorOr<Bytes> DeflateDecompressor::read(Bytes bytes)
ErrorOr<Bytes> DeflateDecompressor::read_some(Bytes bytes)
{
size_t total_read = 0;
while (total_read < bytes.size()) {
@ -225,9 +225,10 @@ ErrorOr<Bytes> DeflateDecompressor::read(Bytes bytes)
if (block_type == 0b00) {
m_input_stream->align_to_byte_boundary();
// FIXME: This should read the entire span.
LittleEndian<u16> length, negated_length;
TRY(m_input_stream->read(length.bytes()));
TRY(m_input_stream->read(negated_length.bytes()));
TRY(m_input_stream->read_some(length.bytes()));
TRY(m_input_stream->read_some(negated_length.bytes()));
if ((length ^ 0xffff) != negated_length)
return Error::from_string_literal("Calculated negated length does not equal stored negated length");
@ -301,7 +302,7 @@ ErrorOr<Bytes> DeflateDecompressor::read(Bytes bytes)
bool DeflateDecompressor::is_eof() const { return m_state == State::Idle && m_read_final_bock; }
ErrorOr<size_t> DeflateDecompressor::write(ReadonlyBytes)
ErrorOr<size_t> DeflateDecompressor::write_some(ReadonlyBytes)
{
return Error::from_errno(EBADF);
}
@ -323,7 +324,7 @@ ErrorOr<ByteBuffer> DeflateDecompressor::decompress_all(ReadonlyBytes bytes)
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (!deflate_stream->is_eof()) {
auto const slice = TRY(deflate_stream->read(buffer));
auto const slice = TRY(deflate_stream->read_some(buffer));
TRY(output_stream.write_entire_buffer(slice));
}
@ -468,12 +469,12 @@ DeflateCompressor::~DeflateCompressor()
VERIFY(m_finished);
}
ErrorOr<Bytes> DeflateCompressor::read(Bytes)
ErrorOr<Bytes> DeflateCompressor::read_some(Bytes)
{
return Error::from_errno(EBADF);
}
ErrorOr<size_t> DeflateCompressor::write(ReadonlyBytes bytes)
ErrorOr<size_t> DeflateCompressor::write_some(ReadonlyBytes bytes)
{
VERIFY(!m_finished);

View file

@ -79,8 +79,8 @@ public:
static ErrorOr<NonnullOwnPtr<DeflateDecompressor>> construct(MaybeOwned<Stream> stream);
~DeflateDecompressor();
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 bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;
@ -144,8 +144,8 @@ public:
static ErrorOr<NonnullOwnPtr<DeflateCompressor>> construct(MaybeOwned<Stream>, CompressionLevel = CompressionLevel::GOOD);
~DeflateCompressor();
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 bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;

View file

@ -60,7 +60,7 @@ GzipDecompressor::~GzipDecompressor()
m_current_member.clear();
}
ErrorOr<Bytes> GzipDecompressor::read(Bytes bytes)
ErrorOr<Bytes> GzipDecompressor::read_some(Bytes bytes)
{
size_t total_read = 0;
while (total_read < bytes.size()) {
@ -70,14 +70,15 @@ ErrorOr<Bytes> GzipDecompressor::read(Bytes bytes)
auto slice = bytes.slice(total_read);
if (m_current_member) {
auto current_slice = TRY(current_member().m_stream->read(slice));
auto current_slice = TRY(current_member().m_stream->read_some(slice));
current_member().m_checksum.update(current_slice);
current_member().m_nread += current_slice.size();
if (current_slice.size() < slice.size()) {
// FIXME: This should read the entire span.
LittleEndian<u32> crc32, input_size;
TRY(m_input_stream->read(crc32.bytes()));
TRY(m_input_stream->read(input_size.bytes()));
TRY(m_input_stream->read_some(crc32.bytes()));
TRY(m_input_stream->read_some(input_size.bytes()));
if (crc32 != current_member().m_checksum.digest())
return Error::from_string_literal("Stored CRC32 does not match the calculated CRC32 of the current member");
@ -95,7 +96,7 @@ ErrorOr<Bytes> GzipDecompressor::read(Bytes bytes)
continue;
} else {
auto current_partial_header_slice = Bytes { m_partial_header, sizeof(BlockHeader) }.slice(m_partial_header_offset);
auto current_partial_header_data = TRY(m_input_stream->read(current_partial_header_slice));
auto current_partial_header_data = TRY(m_input_stream->read_some(current_partial_header_slice));
m_partial_header_offset += current_partial_header_data.size();
if (is_eof())
@ -115,16 +116,18 @@ ErrorOr<Bytes> GzipDecompressor::read(Bytes bytes)
return Error::from_string_literal("Header is not supported by implementation");
if (header.flags & Flags::FEXTRA) {
// FIXME: This should read the entire span.
LittleEndian<u16> subfield_id, length;
TRY(m_input_stream->read(subfield_id.bytes()));
TRY(m_input_stream->read(length.bytes()));
TRY(m_input_stream->read_some(subfield_id.bytes()));
TRY(m_input_stream->read_some(length.bytes()));
TRY(m_input_stream->discard(length));
}
auto discard_string = [&]() -> ErrorOr<void> {
char next_char;
do {
TRY(m_input_stream->read({ &next_char, sizeof(next_char) }));
// FIXME: This should read the entire span.
TRY(m_input_stream->read_some({ &next_char, sizeof(next_char) }));
} while (next_char);
return {};
@ -137,8 +140,9 @@ ErrorOr<Bytes> GzipDecompressor::read(Bytes bytes)
TRY(discard_string());
if (header.flags & Flags::FHCRC) {
// FIXME: This should read the entire span.
LittleEndian<u16> crc16;
TRY(m_input_stream->read(crc16.bytes()));
TRY(m_input_stream->read_some(crc16.bytes()));
// FIXME: we should probably verify this instead of just assuming it matches
}
@ -170,7 +174,7 @@ ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (!gzip_stream->is_eof()) {
auto const data = TRY(gzip_stream->read(buffer));
auto const data = TRY(gzip_stream->read_some(buffer));
TRY(output_stream.write_entire_buffer(data));
}
@ -181,7 +185,7 @@ ErrorOr<ByteBuffer> GzipDecompressor::decompress_all(ReadonlyBytes bytes)
bool GzipDecompressor::is_eof() const { return m_input_stream->is_eof(); }
ErrorOr<size_t> GzipDecompressor::write(ReadonlyBytes)
ErrorOr<size_t> GzipDecompressor::write_some(ReadonlyBytes)
{
return Error::from_errno(EBADF);
}
@ -191,12 +195,12 @@ GzipCompressor::GzipCompressor(MaybeOwned<Stream> stream)
{
}
ErrorOr<Bytes> GzipCompressor::read(Bytes)
ErrorOr<Bytes> GzipCompressor::read_some(Bytes)
{
return Error::from_errno(EBADF);
}
ErrorOr<size_t> GzipCompressor::write(ReadonlyBytes bytes)
ErrorOr<size_t> GzipCompressor::write_some(ReadonlyBytes bytes)
{
BlockHeader header;
header.identification_1 = 0x1f;

View file

@ -45,8 +45,8 @@ public:
GzipDecompressor(NonnullOwnPtr<Stream>);
~GzipDecompressor();
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 bool is_eof() const override;
virtual bool is_open() const override { return true; }
virtual void close() override {};
@ -84,8 +84,8 @@ class GzipCompressor final : public Stream {
public:
GzipCompressor(MaybeOwned<Stream>);
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 bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;

View file

@ -113,21 +113,22 @@ ErrorOr<void> ZlibCompressor::write_header(ZlibCompressionMethod compression_met
// FIXME: Support pre-defined dictionaries.
TRY(m_output_stream->write(header.as_u16.bytes()));
// FIXME: This should write the entire span.
TRY(m_output_stream->write_some(header.as_u16.bytes()));
return {};
}
ErrorOr<Bytes> ZlibCompressor::read(Bytes)
ErrorOr<Bytes> ZlibCompressor::read_some(Bytes)
{
return Error::from_errno(EBADF);
}
ErrorOr<size_t> ZlibCompressor::write(ReadonlyBytes bytes)
ErrorOr<size_t> ZlibCompressor::write_some(ReadonlyBytes bytes)
{
VERIFY(!m_finished);
size_t n_written = TRY(m_compressor->write(bytes));
size_t n_written = TRY(m_compressor->write_some(bytes));
m_adler32_checksum.update(bytes.trim(n_written));
return n_written;
}
@ -154,7 +155,8 @@ ErrorOr<void> ZlibCompressor::finish()
TRY(static_cast<DeflateCompressor*>(m_compressor.ptr())->final_flush());
NetworkOrdered<u32> adler_sum = m_adler32_checksum.digest();
TRY(m_output_stream->write(adler_sum.bytes()));
// FIXME: This should write the entire span.
TRY(m_output_stream->write_some(adler_sum.bytes()));
m_finished = true;

View file

@ -67,8 +67,8 @@ public:
static ErrorOr<NonnullOwnPtr<ZlibCompressor>> construct(MaybeOwned<Stream>, ZlibCompressionLevel = ZlibCompressionLevel::Default);
~ZlibCompressor();
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 bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;

View file

@ -179,10 +179,11 @@ ErrorOr<void> ConfigFile::sync()
TRY(m_file->seek(0, SeekMode::SetPosition));
for (auto& it : m_groups) {
TRY(m_file->write(DeprecatedString::formatted("[{}]\n", it.key).bytes()));
// FIXME: This should write the entire span.
TRY(m_file->write_some(DeprecatedString::formatted("[{}]\n", it.key).bytes()));
for (auto& jt : it.value)
TRY(m_file->write(DeprecatedString::formatted("{}={}\n", jt.key, jt.value).bytes()));
TRY(m_file->write("\n"sv.bytes()));
TRY(m_file->write_some(DeprecatedString::formatted("{}={}\n", jt.key, jt.value).bytes()));
TRY(m_file->write_some("\n"sv.bytes()));
}
m_dirty = false;

View file

@ -169,7 +169,7 @@ private:
#ifdef AK_OS_SERENITY
m_socket->on_ready_to_read = [this] {
u32 length;
auto maybe_bytes_read = m_socket->read({ (u8*)&length, sizeof(length) });
auto maybe_bytes_read = m_socket->read_some({ (u8*)&length, sizeof(length) });
if (maybe_bytes_read.is_error()) {
dbgln("InspectorServerConnection: Failed to read message length from inspector server connection: {}", maybe_bytes_read.error());
shutdown();
@ -186,7 +186,7 @@ private:
VERIFY(bytes_read.size() == sizeof(length));
auto request_buffer = ByteBuffer::create_uninitialized(length).release_value();
maybe_bytes_read = m_socket->read(request_buffer.bytes());
maybe_bytes_read = m_socket->read_some(request_buffer.bytes());
if (maybe_bytes_read.is_error()) {
dbgln("InspectorServerConnection: Failed to read message content from inspector server connection: {}", maybe_bytes_read.error());
shutdown();
@ -221,10 +221,11 @@ public:
auto bytes_to_send = serialized.bytes();
u32 length = bytes_to_send.size();
// FIXME: Propagate errors
auto sent = MUST(m_socket->write({ (u8 const*)&length, sizeof(length) }));
// FIXME: This should write the entire span.
auto sent = MUST(m_socket->write_some({ (u8 const*)&length, sizeof(length) }));
VERIFY(sent == sizeof(length));
while (!bytes_to_send.is_empty()) {
size_t bytes_sent = MUST(m_socket->write(bytes_to_send));
size_t bytes_sent = MUST(m_socket->write_some(bytes_to_send));
bytes_to_send = bytes_to_send.slice(bytes_sent);
}
}

View file

@ -99,7 +99,7 @@ ErrorOr<void> File::open_path(StringView filename, mode_t permissions)
return {};
}
ErrorOr<Bytes> File::read(Bytes buffer)
ErrorOr<Bytes> File::read_some(Bytes buffer)
{
if (!has_flag(m_mode, OpenMode::Read)) {
// NOTE: POSIX says that if the fd is not open for reading, the call
@ -121,7 +121,7 @@ ErrorOr<ByteBuffer> File::read_until_eof(size_t block_size)
return read_until_eof_impl(block_size, potential_file_size);
}
ErrorOr<size_t> File::write(ReadonlyBytes buffer)
ErrorOr<size_t> File::write_some(ReadonlyBytes buffer)
{
if (!has_flag(m_mode, OpenMode::Write)) {
// NOTE: Same deal as Read.

View file

@ -59,9 +59,9 @@ public:
return *this;
}
virtual ErrorOr<Bytes> read(Bytes) override;
virtual ErrorOr<Bytes> read_some(Bytes) override;
virtual ErrorOr<ByteBuffer> read_until_eof(size_t block_size = 4096) override;
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
virtual bool is_eof() const override;
virtual bool is_open() const override;
virtual void close() override;

View file

@ -57,7 +57,7 @@ protected:
void did_fail(Error);
void did_progress(Optional<u32> total_size, u32 downloaded);
ErrorOr<size_t> do_write(ReadonlyBytes bytes) { return m_output_stream.write(bytes); }
ErrorOr<size_t> do_write(ReadonlyBytes bytes) { return m_output_stream.write_some(bytes); }
private:
RefPtr<NetworkResponse> m_response;

View file

@ -102,12 +102,14 @@ ErrorOr<void> send_version_identifier_and_method_selection_message(Core::Socket&
.method_count = 1,
.methods = { to_underlying(method) },
};
auto size = TRY(socket.write({ &message, sizeof(message) }));
// FIXME: This should write the entire span.
auto size = TRY(socket.write_some({ &message, sizeof(message) }));
if (size != sizeof(message))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send version identifier and method selection message");
Socks5InitialResponse response;
size = TRY(socket.read({ &response, sizeof(response) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &response, sizeof(response) })).size();
if (size != sizeof(response))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive initial response");
@ -133,7 +135,8 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
.port = htons(port),
};
auto size = TRY(stream.write({ &header, sizeof(header) }));
// FIXME: This should write the entire span.
auto size = TRY(stream.write_some({ &header, sizeof(header) }));
if (size != sizeof(header))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request header");
@ -142,10 +145,12 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
u8 address_data[2];
address_data[0] = to_underlying(AddressType::DomainName);
address_data[1] = hostname.length();
auto size = TRY(stream.write({ address_data, sizeof(address_data) }));
// FIXME: This should write the entire span.
auto size = TRY(stream.write_some({ address_data, sizeof(address_data) }));
if (size != array_size(address_data))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request address data");
TRY(stream.write({ hostname.characters(), hostname.length() }));
// FIXME: This should write the entire span.
TRY(stream.write_some({ hostname.characters(), hostname.length() }));
return {};
},
[&](u32 ipv4) -> ErrorOr<void> {
@ -153,25 +158,29 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
address_data[0] = to_underlying(AddressType::IPV4);
u32 network_ordered_ipv4 = NetworkOrdered<u32>(ipv4);
memcpy(address_data + 1, &network_ordered_ipv4, sizeof(network_ordered_ipv4));
auto size = TRY(stream.write({ address_data, sizeof(address_data) }));
// FIXME: This should write the entire span.
auto size = TRY(stream.write_some({ address_data, sizeof(address_data) }));
if (size != array_size(address_data))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request address data");
return {};
}));
size = TRY(stream.write({ &trailer, sizeof(trailer) }));
// FIXME: This should write the entire span.
size = TRY(stream.write_some({ &trailer, sizeof(trailer) }));
if (size != sizeof(trailer))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request trailer");
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
TRY(stream.read_entire_buffer(buffer.bytes()));
size = TRY(socket.write({ buffer.data(), buffer.size() }));
// FIXME: This should write the entire span.
size = TRY(socket.write_some({ buffer.data(), buffer.size() }));
if (size != buffer.size())
return Error::from_string_literal("SOCKS negotiation failed: Failed to send connect request");
Socks5ConnectResponseHeader response_header;
size = TRY(socket.read({ &response_header, sizeof(response_header) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &response_header, sizeof(response_header) })).size();
if (size != sizeof(response_header))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response header");
@ -179,26 +188,30 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
return Error::from_string_literal("SOCKS negotiation failed: Invalid version identifier");
u8 response_address_type;
size = TRY(socket.read({ &response_address_type, sizeof(response_address_type) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &response_address_type, sizeof(response_address_type) })).size();
if (size != sizeof(response_address_type))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response address type");
switch (AddressType(response_address_type)) {
case AddressType::IPV4: {
u8 response_address_data[4];
size = TRY(socket.read({ response_address_data, sizeof(response_address_data) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ response_address_data, sizeof(response_address_data) })).size();
if (size != sizeof(response_address_data))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response address data");
break;
}
case AddressType::DomainName: {
u8 response_address_length;
size = TRY(socket.read({ &response_address_length, sizeof(response_address_length) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &response_address_length, sizeof(response_address_length) })).size();
if (size != sizeof(response_address_length))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response address length");
ByteBuffer buffer;
buffer.resize(response_address_length);
size = TRY(socket.read(buffer)).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some(buffer)).size();
if (size != response_address_length)
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response address data");
break;
@ -209,7 +222,8 @@ ErrorOr<Reply> send_connect_request_message(Core::Socket& socket, Core::SOCKSPro
}
u16 bound_port;
size = TRY(socket.read({ &bound_port, sizeof(bound_port) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &bound_port, sizeof(bound_port) })).size();
if (size != sizeof(bound_port))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive connect response bound port");
@ -221,37 +235,44 @@ ErrorOr<u8> send_username_password_authentication_message(Core::Socket& socket,
AllocatingMemoryStream stream;
u8 version = 0x01;
auto size = TRY(stream.write({ &version, sizeof(version) }));
// FIXME: This should write the entire span.
auto size = TRY(stream.write_some({ &version, sizeof(version) }));
if (size != sizeof(version))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
u8 username_length = auth_data.username.length();
size = TRY(stream.write({ &username_length, sizeof(username_length) }));
// FIXME: This should write the entire span.
size = TRY(stream.write_some({ &username_length, sizeof(username_length) }));
if (size != sizeof(username_length))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
size = TRY(stream.write({ auth_data.username.characters(), auth_data.username.length() }));
// FIXME: This should write the entire span.
size = TRY(stream.write_some({ auth_data.username.characters(), auth_data.username.length() }));
if (size != auth_data.username.length())
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
u8 password_length = auth_data.password.length();
size = TRY(stream.write({ &password_length, sizeof(password_length) }));
// FIXME: This should write the entire span.
size = TRY(stream.write_some({ &password_length, sizeof(password_length) }));
if (size != sizeof(password_length))
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
size = TRY(stream.write({ auth_data.password.characters(), auth_data.password.length() }));
// FIXME: This should write the entire span.
size = TRY(stream.write_some({ auth_data.password.characters(), auth_data.password.length() }));
if (size != auth_data.password.length())
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
auto buffer = TRY(ByteBuffer::create_uninitialized(stream.used_buffer_size()));
TRY(stream.read_entire_buffer(buffer.bytes()));
size = TRY(socket.write(buffer));
// FIXME: This should write the entire span.
size = TRY(socket.write_some(buffer));
if (size != buffer.size())
return Error::from_string_literal("SOCKS negotiation failed: Failed to send username/password authentication message");
Socks5UsernamePasswordResponse response;
size = TRY(socket.read({ &response, sizeof(response) })).size();
// FIXME: This should read the entire span.
size = TRY(socket.read_some({ &response, sizeof(response) })).size();
if (size != sizeof(response))
return Error::from_string_literal("SOCKS negotiation failed: Failed to receive username/password authentication response");

View file

@ -37,8 +37,8 @@ public:
virtual ~SOCKSProxyClient() override;
// ^Stream::Stream
virtual ErrorOr<Bytes> read(Bytes bytes) override { return m_socket.read(bytes); }
virtual ErrorOr<size_t> write(ReadonlyBytes bytes) override { return m_socket.write(bytes); }
virtual ErrorOr<Bytes> read_some(Bytes bytes) override { return m_socket.read_some(bytes); }
virtual ErrorOr<size_t> write_some(ReadonlyBytes bytes) override { return m_socket.write_some(bytes); }
virtual bool is_eof() const override { return m_socket.is_eof(); }
virtual bool is_open() const override { return m_socket.is_open(); }
virtual void close() override { m_socket.close(); }

View file

@ -176,8 +176,8 @@ public:
return *this;
}
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual ErrorOr<Bytes> read_some(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
virtual ErrorOr<size_t> write_some(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual bool is_eof() const override { return m_helper.is_eof(); }
virtual bool is_open() const override { return m_helper.is_open(); };
virtual void close() override { m_helper.close(); };
@ -236,7 +236,7 @@ public:
return *this;
}
virtual ErrorOr<Bytes> read(Bytes buffer) override
virtual ErrorOr<Bytes> read_some(Bytes buffer) override
{
auto pending_bytes = TRY(this->pending_bytes());
if (pending_bytes > buffer.size()) {
@ -251,7 +251,7 @@ public:
return m_helper.read(buffer, default_flags());
}
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual ErrorOr<size_t> write_some(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual bool is_eof() const override { return m_helper.is_eof(); }
virtual bool is_open() const override { return m_helper.is_open(); }
virtual void close() override { m_helper.close(); }
@ -310,8 +310,8 @@ public:
return *this;
}
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual ErrorOr<Bytes> read_some(Bytes buffer) override { return m_helper.read(buffer, default_flags()); }
virtual ErrorOr<size_t> write_some(ReadonlyBytes buffer) override { return m_helper.write(buffer, default_flags()); }
virtual bool is_eof() const override { return m_helper.is_eof(); }
virtual bool is_open() const override { return m_helper.is_open(); }
virtual void close() override { m_helper.close(); }
@ -398,8 +398,8 @@ public:
return *this;
}
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(); }
@ -483,8 +483,8 @@ public:
return {};
}
virtual ErrorOr<Bytes> read(Bytes buffer) override { return m_socket.read(move(buffer)); }
virtual ErrorOr<size_t> write(ReadonlyBytes buffer) override { return m_socket.write(buffer); }
virtual ErrorOr<Bytes> read_some(Bytes buffer) override { return m_socket.read(move(buffer)); }
virtual ErrorOr<size_t> write_some(ReadonlyBytes buffer) override { return m_socket.write(buffer); }
virtual bool is_eof() const override { return m_socket.is_eof(); }
virtual bool is_open() const override { return m_socket.is_open(); }
virtual void close() override { m_socket.close(); }

View file

@ -1593,8 +1593,9 @@ ErrorOr<void> TextEditor::write_to_file(Core::File& file)
// A size 0 file doesn't need a data copy.
} else {
for (size_t i = 0; i < line_count(); ++i) {
TRY(file.write(line(i).to_utf8().bytes()));
TRY(file.write("\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(line(i).to_utf8().bytes()));
TRY(file.write_some("\n"sv.bytes()));
}
}
document().set_unmodified();

View file

@ -65,7 +65,7 @@ ErrorOr<String> Job::read_line(size_t size)
ErrorOr<ByteBuffer> Job::receive(size_t size)
{
ByteBuffer buffer = TRY(ByteBuffer::create_uninitialized(size));
auto nread = TRY(m_socket->read(buffer)).size();
auto nread = TRY(m_socket->read_some(buffer)).size();
return buffer.slice(0, nread);
}

View file

@ -184,7 +184,7 @@ ErrorOr<ByteBuffer> Job::receive(size_t size)
auto buffer = TRY(ByteBuffer::create_uninitialized(size));
size_t nread;
do {
auto result = m_socket->read(buffer);
auto result = m_socket->read_some(buffer);
if (result.is_error() && result.error().is_errno() && result.error().code() == EINTR)
continue;
nread = TRY(result).size();

View file

@ -60,7 +60,8 @@ ErrorOr<void> Client::on_ready_to_receive()
auto pending_bytes = TRY(m_socket->pending_bytes());
auto receive_buffer = TRY(m_buffer.get_bytes_for_writing(pending_bytes));
TRY(m_socket->read(receive_buffer));
// FIXME: This should read the entire span.
TRY(m_socket->read_some(receive_buffer));
// Once we get server hello we can start sending.
if (m_connect_pending) {
@ -145,8 +146,9 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
ErrorOr<void> Client::send_raw(StringView data)
{
TRY(m_socket->write(data.bytes()));
TRY(m_socket->write("\r\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(data.bytes()));
TRY(m_socket->write_some("\r\n"sv.bytes()));
return {};
}

View file

@ -74,7 +74,7 @@ ErrorOr<void> ConnectionBase::post_message(MessageBuffer buffer)
int writes_done = 0;
size_t initial_size = bytes_to_write.size();
while (!bytes_to_write.is_empty()) {
auto maybe_nwritten = m_socket->write(bytes_to_write);
auto maybe_nwritten = m_socket->write_some(bytes_to_write);
writes_done++;
if (maybe_nwritten.is_error()) {
auto error = maybe_nwritten.release_error();

View file

@ -680,7 +680,8 @@ ThrowCompletionOr<String> ConsoleClient::generically_format_values(MarkedVector<
bool first = true;
for (auto const& value : values) {
if (!first)
TRY_OR_THROW_OOM(vm, stream.write(" "sv.bytes()));
// FIXME: This should write the entire span.
TRY_OR_THROW_OOM(vm, stream.write_some(" "sv.bytes()));
TRY_OR_THROW_OOM(vm, JS::print(value, ctx));
first = false;
}

View file

@ -148,7 +148,7 @@ ErrorOr<void> js_out(JS::PrintContext& print_context, CheckedFormatString<Args..
auto bytes = formatted.bytes();
while (!bytes.is_empty())
bytes = bytes.slice(TRY(print_context.stream.write(bytes)));
bytes = bytes.slice(TRY(print_context.stream.write_some(bytes)));
return {};
}

View file

@ -534,7 +534,7 @@ void Editor::edit_in_external_editor()
builder.append(Utf32View { m_buffer.data(), m_buffer.size() });
auto bytes = builder.string_view().bytes();
while (!bytes.is_empty()) {
auto nwritten = stream->write(bytes).release_value_but_fixme_should_propagate_errors();
auto nwritten = stream->write_some(bytes).release_value_but_fixme_should_propagate_errors();
bytes = bytes.slice(nwritten);
}
lseek(fd, 0, SEEK_SET);

View file

@ -51,7 +51,8 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
// the suggestion list to fit in the prompt line.
auto start = max_line_count - m_prompt_lines_at_suggestion_initiation;
for (size_t i = start; i < max_line_count; ++i)
TRY(stderr_stream->write("\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(stderr_stream->write_some("\n"sv.bytes()));
lines_used += max_line_count;
longest_suggestion_length = 0;
}
@ -99,7 +100,8 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
if (next_column > m_num_columns) {
auto lines = (suggestion.text_view.length() + m_num_columns - 1) / m_num_columns;
lines_used += lines;
TRY(stderr_stream->write("\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(stderr_stream->write_some("\n"sv.bytes()));
num_printed = 0;
}
@ -115,11 +117,13 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
if (spans_entire_line) {
num_printed += m_num_columns;
TRY(stderr_stream->write(suggestion.text_string.bytes()));
TRY(stderr_stream->write(suggestion.display_trivia_string.bytes()));
// FIXME: This should write the entire span.
TRY(stderr_stream->write_some(suggestion.text_string.bytes()));
TRY(stderr_stream->write_some(suggestion.display_trivia_string.bytes()));
} else {
auto field = DeprecatedString::formatted("{: <{}} {}", suggestion.text_string, longest_suggestion_byte_length_without_trivia, suggestion.display_trivia_string);
TRY(stderr_stream->write(DeprecatedString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes()));
// FIXME: This should write the entire span.
TRY(stderr_stream->write_some(DeprecatedString::formatted("{: <{}}", field, longest_suggestion_byte_length + 2).bytes()));
num_printed += longest_suggestion_length + 2;
}
@ -150,7 +154,8 @@ ErrorOr<void> XtermSuggestionDisplay::display(SuggestionManager const& manager)
TRY(VT::move_absolute(m_origin_row + lines_used, m_num_columns - string.length() - 1, *stderr_stream));
TRY(VT::apply_style({ Style::Background(Style::XtermColor::Green) }, *stderr_stream));
TRY(stderr_stream->write(string.bytes()));
// FIXME: This should write the entire span.
TRY(stderr_stream->write_some(string.bytes()));
TRY(VT::apply_style(Style::reset_style(), *stderr_stream));
}

View file

@ -45,7 +45,7 @@ void Request::stream_into(Stream& stream)
constexpr size_t buffer_size = 256 * KiB;
static char buf[buffer_size];
do {
auto result = m_internal_stream_data->read_stream->read({ buf, buffer_size });
auto result = m_internal_stream_data->read_stream->read_some({ buf, buffer_size });
if (result.is_error() && (!result.error().is_errno() || (result.error().is_errno() && result.error().code() != EINTR)))
break;
if (result.is_error())

View file

@ -91,7 +91,8 @@ ErrorOr<ByteBuffer> Heap::read_block(u32 block)
TRY(seek_block(block));
auto buffer = TRY(ByteBuffer::create_uninitialized(BLOCKSIZE));
auto bytes = TRY(m_file->read(buffer));
// FIXME: This should read the entire span.
auto bytes = TRY(m_file->read_some(buffer));
dbgln_if(SQL_DEBUG, "{:hex-dump}", bytes.trim(8));
TRY(buffer.try_resize(bytes.size()));
@ -123,7 +124,8 @@ ErrorOr<void> Heap::write_block(u32 block, ByteBuffer& buffer)
}
dbgln_if(SQL_DEBUG, "{:hex-dump}", buffer.bytes().trim(8));
TRY(m_file->write(buffer));
// FIXME: This should write the entire span.
TRY(m_file->write_some(buffer));
if (block == m_end_of_file)
m_end_of_file++;

View file

@ -67,7 +67,8 @@ static ErrorOr<void> launch_server(DeprecatedString const& socket_path, Deprecat
if (server_pid != 0) {
auto server_pid_file = TRY(Core::File::open(pid_path, Core::File::OpenMode::Write));
TRY(server_pid_file->write(DeprecatedString::number(server_pid).bytes()));
// FIXME: This should write the entire span.
TRY(server_pid_file->write_some(DeprecatedString::number(server_pid).bytes()));
TRY(Core::System::kill(getpid(), SIGTERM));
}

View file

@ -18,7 +18,7 @@ constexpr static size_t MaximumApplicationDataChunkSize = 16 * KiB;
namespace TLS {
ErrorOr<Bytes> TLSv12::read(Bytes bytes)
ErrorOr<Bytes> TLSv12::read_some(Bytes bytes)
{
m_eof = false;
auto size_to_read = min(bytes.size(), m_context.application_buffer.size());
@ -53,7 +53,7 @@ DeprecatedString TLSv12::read_line(size_t max_size)
return line;
}
ErrorOr<size_t> TLSv12::write(ReadonlyBytes bytes)
ErrorOr<size_t> TLSv12::write_some(ReadonlyBytes bytes)
{
if (m_context.connection_status != ConnectionStatus::Established) {
dbgln_if(TLS_DEBUG, "write request while not connected");
@ -190,7 +190,7 @@ ErrorOr<void> TLSv12::read_from_socket()
Bytes read_bytes {};
auto& stream = underlying_stream();
do {
auto result = stream.read(bytes);
auto result = stream.read_some(bytes);
if (result.is_error()) {
if (result.error().is_errno() && result.error().code() != EINTR) {
if (result.error().code() != EAGAIN)
@ -291,7 +291,7 @@ ErrorOr<bool> TLSv12::flush()
Optional<AK::Error> error;
size_t written;
do {
auto result = stream.write(out_bytes);
auto result = stream.write_some(out_bytes);
if (result.is_error() && result.error().code() != EINTR && result.error().code() != EAGAIN) {
error = result.release_error();
dbgln("TLS Socket write error: {}", *error);

View file

@ -360,12 +360,12 @@ 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) override;
virtual ErrorOr<Bytes> read_some(Bytes) override;
/// 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) override;
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override;
virtual bool is_eof() const override { return m_context.application_buffer.is_empty() && (m_context.connection_finished || underlying_stream().is_eof()); }

View file

@ -220,7 +220,8 @@ inline ByteBuffer load_entire_file(StringView path)
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto file_size = TRY(file->size());
auto content = TRY(ByteBuffer::create_uninitialized(file_size));
TRY(file->read(content.bytes()));
// FIXME: This should read the entire span.
TRY(file->read_some(content.bytes()));
return content;
};

View file

@ -795,7 +795,7 @@ ParseResult<CustomSection> CustomSection::parse(Stream& stream)
while (!stream.is_eof()) {
char buf[16];
auto span_or_error = stream.read({ buf, 16 });
auto span_or_error = stream.read_some({ buf, 16 });
if (span_or_error.is_error())
break;
auto size = span_or_error.release_value().size();

View file

@ -81,7 +81,7 @@ public:
void unread(ReadonlyBytes data) { m_buffer.append(data.data(), data.size()); }
private:
virtual ErrorOr<Bytes> read(Bytes bytes) override
virtual ErrorOr<Bytes> read_some(Bytes bytes) override
{
auto original_bytes = bytes;
@ -95,7 +95,7 @@ private:
bytes_read_from_buffer = read_size;
}
return original_bytes.trim(TRY(m_stream.read(bytes)).size() + bytes_read_from_buffer);
return original_bytes.trim(TRY(m_stream.read_some(bytes)).size() + bytes_read_from_buffer);
}
virtual bool is_eof() const override
@ -116,7 +116,7 @@ private:
return m_stream.discard(count - bytes_discarded_from_buffer);
}
virtual ErrorOr<size_t> write(ReadonlyBytes) override
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override
{
return Error::from_errno(EBADF);
}
@ -144,10 +144,10 @@ public:
}
private:
ErrorOr<Bytes> read(Bytes bytes) override
ErrorOr<Bytes> read_some(Bytes bytes) override
{
auto to_read = min(m_bytes_left, bytes.size());
auto read_bytes = TRY(m_stream.read(bytes.slice(0, to_read)));
auto read_bytes = TRY(m_stream.read_some(bytes.slice(0, to_read)));
m_bytes_left -= read_bytes.size();
return read_bytes;
}
@ -165,7 +165,7 @@ private:
return m_stream.discard(count);
}
virtual ErrorOr<size_t> write(ReadonlyBytes) override
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override
{
return Error::from_errno(EBADF);
}

View file

@ -213,7 +213,7 @@ ErrorOr<void, Client::WrappedError> Client::on_ready_to_read()
if (!TRY(m_socket->can_read_without_blocking()))
break;
auto data = TRY(m_socket->read(buffer));
auto data = TRY(m_socket->read_some(buffer));
TRY(builder.try_append(StringView { data }));
if (m_socket->is_eof())
@ -279,10 +279,11 @@ ErrorOr<void, Client::WrappedError> Client::send_success_response(JsonValue resu
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
TRY(m_socket->write(builder_contents));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
while (!content.is_empty()) {
auto bytes_sent = TRY(m_socket->write(content.bytes()));
auto bytes_sent = TRY(m_socket->write_some(content.bytes()));
content = content.substring_view(bytes_sent);
}
@ -319,8 +320,9 @@ ErrorOr<void, Client::WrappedError> Client::send_error_response(Error const& err
header_builder.appendff("Content-Length: {}\r\n", content_builder.length());
header_builder.append("\r\n"sv);
TRY(m_socket->write(TRY(header_builder.to_byte_buffer())));
TRY(m_socket->write(TRY(content_builder.to_byte_buffer())));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(TRY(header_builder.to_byte_buffer())));
TRY(m_socket->write_some(TRY(content_builder.to_byte_buffer())));
log_response(error.http_status);
return {};

View file

@ -76,7 +76,7 @@ void WebSocketImplSerenity::connect(ConnectionInfo const& connection_info)
ErrorOr<ByteBuffer> WebSocketImplSerenity::read(int max_size)
{
auto buffer = TRY(ByteBuffer::create_uninitialized(max_size));
auto read_bytes = TRY(m_socket->read(buffer));
auto read_bytes = TRY(m_socket->read_some(buffer));
return buffer.slice(0, read_bytes.size());
}

View file

@ -31,7 +31,7 @@ ErrorOr<void> Client::drain_socket()
auto buffer = TRY(ByteBuffer::create_uninitialized(1024));
while (TRY(m_socket->can_read_without_blocking())) {
auto bytes_read = TRY(m_socket->read(buffer));
auto bytes_read = TRY(m_socket->read_some(buffer));
dbgln("Read {} bytes.", bytes_read.size());
@ -40,7 +40,8 @@ ErrorOr<void> Client::drain_socket()
break;
}
TRY(m_socket->write(bytes_read));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(bytes_read));
}
return {};

View file

@ -237,10 +237,11 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
while (true) {
print_progress();
auto bytes_read = TRY(source_file->read(buffer.bytes()));
auto bytes_read = TRY(source_file->read_some(buffer.bytes()));
if (bytes_read.is_empty())
break;
if (auto result = destination_file->write(bytes_read); result.is_error()) {
// FIXME: This should write the entire span.
if (auto result = destination_file->write_some(bytes_read); result.is_error()) {
// FIXME: Return the formatted string directly. There is no way to do this right now without the temporary going out of scope and being destroyed.
report_warning(DeprecatedString::formatted("Failed to write to destination file: {}", result.error()));
return result.release_error();

View file

@ -27,7 +27,8 @@ InspectableProcess::InspectableProcess(pid_t pid, NonnullOwnPtr<Core::LocalSocke
m_socket->on_ready_to_read = [this] {
char c;
[[maybe_unused]] auto buffer = m_socket->read({ &c, 1 });
// FIXME: This should read the entire span.
[[maybe_unused]] auto buffer = m_socket->read_some({ &c, 1 });
if (m_socket->is_eof()) {
Core::deferred_invoke([pid = this->m_pid] { g_processes.remove(pid); });
return;
@ -44,7 +45,8 @@ DeprecatedString InspectableProcess::wait_for_response()
}
u32 length {};
auto length_bytes_read = m_socket->read({ (u8*)&length, sizeof(length) }).release_value_but_fixme_should_propagate_errors();
// FIXME: This should read the entire span.
auto length_bytes_read = m_socket->read_some({ (u8*)&length, sizeof(length) }).release_value_but_fixme_should_propagate_errors();
if (length_bytes_read.size() != sizeof(length)) {
dbgln("InspectableProcess got malformed data: PID {}", m_pid);
m_socket->close();
@ -55,7 +57,7 @@ DeprecatedString InspectableProcess::wait_for_response()
auto remaining_data_buffer = data_buffer.bytes();
while (!remaining_data_buffer.is_empty()) {
auto maybe_bytes_read = m_socket->read(remaining_data_buffer);
auto maybe_bytes_read = m_socket->read_some(remaining_data_buffer);
if (maybe_bytes_read.is_error()) {
dbgln("InspectableProcess::wait_for_response: Failed to read data: {}", maybe_bytes_read.error());
break;
@ -80,8 +82,9 @@ void InspectableProcess::send_request(JsonObject const& request)
u32 length = serialized.length();
// FIXME: Propagate errors
MUST(m_socket->write({ (u8 const*)&length, sizeof(length) }));
MUST(m_socket->write(serialized.bytes()));
// FIXME: This should write the entire span.
MUST(m_socket->write_some({ (u8 const*)&length, sizeof(length) }));
MUST(m_socket->write_some(serialized.bytes()));
}
}

View file

@ -239,10 +239,11 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, DeprecatedString
auto udp_socket = TRY(Core::UDPSocket::connect(nameserver, 53, Time::from_seconds(1)));
TRY(udp_socket->set_blocking(true));
TRY(udp_socket->write(buffer));
// FIXME: This should write the entire span.
TRY(udp_socket->write_some(buffer));
u8 response_buffer[4096];
int nrecv = TRY(udp_socket->read({ response_buffer, sizeof(response_buffer) })).size();
int nrecv = TRY(udp_socket->read_some({ response_buffer, sizeof(response_buffer) })).size();
if (udp_socket->is_eof())
return Vector<Answer> {};

View file

@ -77,7 +77,7 @@ ErrorOr<void> Client::drain_socket()
auto buffer = TRY(ByteBuffer::create_uninitialized(1024));
while (TRY(m_socket->can_read_without_blocking())) {
auto read_bytes = TRY(m_socket->read(buffer));
auto read_bytes = TRY(m_socket->read_some(buffer));
m_parser.write(StringView { read_bytes });
@ -161,7 +161,8 @@ ErrorOr<void> Client::send_data(StringView data)
}
if (fast) {
TRY(m_socket->write({ data.characters_without_null_termination(), data.length() }));
// FIXME: This should write the entire span.
TRY(m_socket->write_some({ data.characters_without_null_termination(), data.length() }));
return {};
}
@ -183,7 +184,8 @@ ErrorOr<void> Client::send_data(StringView data)
}
auto builder_contents = TRY(builder.to_byte_buffer());
TRY(m_socket->write(builder_contents));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
return {};
}
@ -204,7 +206,8 @@ ErrorOr<void> Client::send_commands(Vector<Command> commands)
}
VERIFY(TRY(stream.tell()) == buffer.size());
TRY(m_socket->write({ buffer.data(), buffer.size() }));
// FIXME: This should write the entire span.
TRY(m_socket->write_some({ buffer.data(), buffer.size() }));
return {};
}

View file

@ -192,18 +192,19 @@ ErrorOr<void> Client::send_response(Stream& response, HTTP::HttpRequest const& r
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
TRY(m_socket->write(builder_contents));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
log_response(200, request);
char buffer[PAGE_SIZE];
do {
auto size = TRY(response.read({ buffer, sizeof(buffer) })).size();
auto size = TRY(response.read_some({ buffer, sizeof(buffer) })).size();
if (response.is_eof() && size == 0)
break;
ReadonlyBytes write_buffer { buffer, size };
while (!write_buffer.is_empty()) {
auto nwritten = TRY(m_socket->write(write_buffer));
auto nwritten = TRY(m_socket->write_some(write_buffer));
if (nwritten == 0) {
dbgln("EEEEEE got 0 bytes written!");
@ -234,7 +235,8 @@ ErrorOr<void> Client::send_redirect(StringView redirect_path, HTTP::HttpRequest
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
TRY(m_socket->write(builder_contents));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
log_response(301, request);
return {};
@ -363,8 +365,9 @@ ErrorOr<void> Client::send_error_response(unsigned code, HTTP::HttpRequest const
header_builder.append("Content-Type: text/html; charset=UTF-8\r\n"sv);
header_builder.appendff("Content-Length: {}\r\n", content_builder.length());
header_builder.append("\r\n"sv);
TRY(m_socket->write(TRY(header_builder.to_byte_buffer())));
TRY(m_socket->write(TRY(content_builder.to_byte_buffer())));
// FIXME: This should write the entire span.
TRY(m_socket->write_some(TRY(header_builder.to_byte_buffer())));
TRY(m_socket->write_some(TRY(content_builder.to_byte_buffer())));
log_response(code, request);
return {};

View file

@ -40,7 +40,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Array<u8, 32768> buffer;
for (auto const& file : files) {
while (!file->is_eof()) {
auto const buffer_span = TRY(file->read(buffer));
auto const buffer_span = TRY(file->read_some(buffer));
out("{:s}", buffer_span);
}
}

View file

@ -66,13 +66,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Array<u8, PAGE_SIZE> buffer;
if (!verify_from_paths) {
while (!file->is_eof())
hash.update(TRY(file->read(buffer)));
hash.update(TRY(file->read_some(buffer)));
outln("{:hex-dump} {}", hash.digest().bytes(), path);
} else {
StringBuilder checksum_list_contents;
Array<u8, 1> checksum_list_buffer;
while (!file->is_eof())
checksum_list_contents.append(TRY(file->read(checksum_list_buffer)).data()[0]);
checksum_list_contents.append(TRY(file->read_some(checksum_list_buffer)).data()[0]);
Vector<StringView> const lines = checksum_list_contents.string_view().split_view("\n"sv);
for (size_t i = 0; i < lines.size(); ++i) {
@ -96,7 +96,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto file_from_filename = file_from_filename_or_error.release_value();
hash.reset();
while (!file_from_filename->is_eof())
hash.update(TRY(file_from_filename->read(buffer)));
hash.update(TRY(file_from_filename->read_some(buffer)));
if (DeprecatedString::formatted("{:hex-dump}", hash.digest().bytes()) == line[0])
outln("{}: OK", filename);
else {

View file

@ -59,7 +59,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (algorithm == "crc32") {
Crypto::Checksum::CRC32 crc32;
while (!file->is_eof()) {
auto data_or_error = file->read(buffer);
auto data_or_error = file->read_some(buffer);
if (data_or_error.is_error()) {
warnln("{}: Failed to read {}: {}", arguments.strings[0], filepath, data_or_error.error());
fail = true;
@ -72,7 +72,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} else if (algorithm == "adler32") {
Crypto::Checksum::Adler32 adler32;
while (!file->is_eof()) {
auto data_or_error = file->read(buffer);
auto data_or_error = file->read_some(buffer);
if (data_or_error.is_error()) {
warnln("{}: Failed to read {}: {}", arguments.strings[0], filepath, data_or_error.error());
fail = true;

View file

@ -75,8 +75,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
};
while (true) {
TRY(file1->read(buffer1));
TRY(file2->read(buffer2));
TRY(file1->read_some(buffer1));
TRY(file2->read_some(buffer2));
if (file1->is_eof() && file2->is_eof())
break;

View file

@ -187,7 +187,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
} else if (!file_size_in_bytes) {
outln("{}: empty", path);
} else {
auto bytes = TRY(file->read(buffer));
auto bytes = TRY(file->read_some(buffer));
auto file_name_guess = Core::guess_mime_type_based_on_filename(path);
auto mime_type = Core::guess_mime_type_based_on_sniffed_bytes(bytes).value_or(file_name_guess);
auto human_readable_description = get_description_from_mime_type(mime_type, path).value_or(mime_type);

View file

@ -28,7 +28,8 @@ static ErrorOr<bool> format_file(StringView path, bool inplace)
return true;
TRY(file->seek(0, SeekMode::SetPosition));
TRY(file->truncate(0));
TRY(file->write(formatted_gml.bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(formatted_gml.bytes()));
} else {
out("{}", formatted_gml);
}

View file

@ -17,7 +17,7 @@ static ErrorOr<void> decompress_file(NonnullOwnPtr<Core::File> input_stream, Str
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
while (!gzip_stream.is_eof()) {
auto span = TRY(gzip_stream.read(buffer));
auto span = TRY(gzip_stream.read_some(buffer));
TRY(output_stream.write_entire_buffer(span));
}

View file

@ -174,7 +174,8 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor
auto output_file = MUST(Core::File::open(output_file_path, Core::File::OpenMode::Write));
auto image_buffer = MUST(Gfx::PNGWriter::encode(*screenshot));
MUST(output_file->write(image_buffer.bytes()));
// FIXME: This should write the entire buffer.
MUST(output_file->write_some(image_buffer.bytes()));
} else {
warnln("No screenshot available");
}

View file

@ -86,7 +86,7 @@ ErrorOr<int> serenity_main(Main::Arguments args)
}
bytes = contents.span().slice(0, bytes_to_read);
bytes = TRY(file->read(bytes));
bytes = TRY(file->read_some(bytes));
total_bytes_read += bytes.size();

View file

@ -188,7 +188,8 @@ static ErrorOr<void> write_to_file(String const& path)
for (size_t i = 0; i < g_repl_statements.size(); i++) {
auto line = g_repl_statements[i].bytes();
if (line.size() > 0 && i != g_repl_statements.size() - 1) {
TRY(file->write(line));
// FIXME: This should write the entire span.
TRY(file->write_some(line));
}
if (i != g_repl_statements.size() - 1) {
TRY(file->write_value('\n'));

View file

@ -82,7 +82,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto nread = TRY(Core::System::read(STDIN_FILENO, buffer_span));
buffer_span = buffer_span.trim(nread);
TRY(socket->write({ buffer_span.data(), static_cast<size_t>(nread) }));
// FIXME: This should write the entire span.
TRY(socket->write_some({ buffer_span.data(), static_cast<size_t>(nread) }));
}
}

View file

@ -112,18 +112,18 @@ 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
{
// Pretend that we wrote the whole buffer if the condition is untrue.
if (!m_condition())
return bytes.size();
return m_stream->write(bytes);
return m_stream->write_some(bytes);
}
virtual bool is_eof() const override

View file

@ -14,7 +14,8 @@ ErrorOr<int> serenity_main(Main::Arguments)
auto file = TRY(Core::File::open("/sys/kernel/power_state"sv, Core::File::OpenMode::Write));
const DeprecatedString file_contents = "1";
TRY(file->write(file_contents.bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(file_contents.bytes()));
file->close();
return 0;

View file

@ -141,8 +141,9 @@ ErrorOr<int> serenity_main(Main::Arguments args)
if (maybe_output_file.has_value()) {
auto const& output_file = maybe_output_file.value();
TRY(output_file->write(result.bytes()));
TRY(output_file->write("\n"sv.bytes()));
// FIXME: This should write the entire span.
TRY(output_file->write_some(result.bytes()));
TRY(output_file->write_some("\n"sv.bytes()));
}
}
}

View file

@ -167,7 +167,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
auto& file = *file_or_error.value();
TRY(file.write(encoded_bitmap.bytes()));
// FIXME: This should write the entire span.
TRY(file.write_some(encoded_bitmap.bytes()));
if (edit_image)
TRY(Core::Process::spawn("/bin/PixelPaint"sv, Array { output_path }));

View file

@ -18,7 +18,8 @@ ErrorOr<int> serenity_main(Main::Arguments)
auto file = TRY(Core::File::open("/sys/kernel/power_state"sv, Core::File::OpenMode::Write));
const DeprecatedString file_contents = "2";
TRY(file->write(file_contents.bytes()));
// FIXME: This should write the entire span.
TRY(file->write_some(file_contents.bytes()));
file->close();
return 0;

Some files were not shown because too many files have changed in this diff Show more