diff options
Diffstat (limited to 'Userland/Libraries')
39 files changed, 189 insertions, 139 deletions
diff --git a/Userland/Libraries/LibArchive/TarStream.cpp b/Userland/Libraries/LibArchive/TarStream.cpp index f2c7725cef..1515185f2f 100644 --- a/Userland/Libraries/LibArchive/TarStream.cpp +++ b/Userland/Libraries/LibArchive/TarStream.cpp @@ -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 {}; diff --git a/Userland/Libraries/LibArchive/TarStream.h b/Userland/Libraries/LibArchive/TarStream.h index 61e104b35b..45cc1eb111 100644 --- a/Userland/Libraries/LibArchive/TarStream.h +++ b/Userland/Libraries/LibArchive/TarStream.h @@ -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 {}; diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index 1032981530..b530db5df2 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -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); } diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp index 33af341fdc..674f398ae2 100644 --- a/Userland/Libraries/LibAudio/MP3Loader.cpp +++ b/Userland/Libraries/LibAudio/MP3Loader.cpp @@ -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). diff --git a/Userland/Libraries/LibCompress/Brotli.cpp b/Userland/Libraries/LibCompress/Brotli.cpp index ee16bff271..6221bc15f7 100644 --- a/Userland/Libraries/LibCompress/Brotli.cpp +++ b/Userland/Libraries/LibCompress/Brotli.cpp @@ -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"); diff --git a/Userland/Libraries/LibCompress/Brotli.h b/Userland/Libraries/LibCompress/Brotli.h index 735abf9aa2..e1bbe00350 100644 --- a/Userland/Libraries/LibCompress/Brotli.h +++ b/Userland/Libraries/LibCompress/Brotli.h @@ -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(); } diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index 189a0d2fa8..b790d317f4 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -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); diff --git a/Userland/Libraries/LibCompress/Deflate.h b/Userland/Libraries/LibCompress/Deflate.h index 1e165f9a7a..c62f1bd34e 100644 --- a/Userland/Libraries/LibCompress/Deflate.h +++ b/Userland/Libraries/LibCompress/Deflate.h @@ -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; diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp index 0fb1980f4b..56f6daa535 100644 --- a/Userland/Libraries/LibCompress/Gzip.cpp +++ b/Userland/Libraries/LibCompress/Gzip.cpp @@ -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; diff --git a/Userland/Libraries/LibCompress/Gzip.h b/Userland/Libraries/LibCompress/Gzip.h index 2a297103ef..85a33eae90 100644 --- a/Userland/Libraries/LibCompress/Gzip.h +++ b/Userland/Libraries/LibCompress/Gzip.h @@ -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; diff --git a/Userland/Libraries/LibCompress/Zlib.cpp b/Userland/Libraries/LibCompress/Zlib.cpp index 04fa6be768..39df8779b6 100644 --- a/Userland/Libraries/LibCompress/Zlib.cpp +++ b/Userland/Libraries/LibCompress/Zlib.cpp @@ -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; diff --git a/Userland/Libraries/LibCompress/Zlib.h b/Userland/Libraries/LibCompress/Zlib.h index 44eb4e1bf4..2039973f2b 100644 --- a/Userland/Libraries/LibCompress/Zlib.h +++ b/Userland/Libraries/LibCompress/Zlib.h @@ -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; diff --git a/Userland/Libraries/LibCore/ConfigFile.cpp b/Userland/Libraries/LibCore/ConfigFile.cpp index a610187027..faa333a225 100644 --- a/Userland/Libraries/LibCore/ConfigFile.cpp +++ b/Userland/Libraries/LibCore/ConfigFile.cpp @@ -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; diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index dd5bb3acb1..b5a0c98521 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -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); } } diff --git a/Userland/Libraries/LibCore/File.cpp b/Userland/Libraries/LibCore/File.cpp index d9eba43da0..7ce5bb42dc 100644 --- a/Userland/Libraries/LibCore/File.cpp +++ b/Userland/Libraries/LibCore/File.cpp @@ -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. diff --git a/Userland/Libraries/LibCore/File.h b/Userland/Libraries/LibCore/File.h index 880aad25a6..22be6a5ec5 100644 --- a/Userland/Libraries/LibCore/File.h +++ b/Userland/Libraries/LibCore/File.h @@ -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; diff --git a/Userland/Libraries/LibCore/NetworkJob.h b/Userland/Libraries/LibCore/NetworkJob.h index 5b013273be..a7c10de959 100644 --- a/Userland/Libraries/LibCore/NetworkJob.h +++ b/Userland/Libraries/LibCore/NetworkJob.h @@ -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; diff --git a/Userland/Libraries/LibCore/SOCKSProxyClient.cpp b/Userland/Libraries/LibCore/SOCKSProxyClient.cpp index 61f3cfaa6c..532d12604f 100644 --- a/Userland/Libraries/LibCore/SOCKSProxyClient.cpp +++ b/Userland/Libraries/LibCore/SOCKSProxyClient.cpp @@ -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"); diff --git a/Userland/Libraries/LibCore/SOCKSProxyClient.h b/Userland/Libraries/LibCore/SOCKSProxyClient.h index aff0bf1a64..24b47bb606 100644 --- a/Userland/Libraries/LibCore/SOCKSProxyClient.h +++ b/Userland/Libraries/LibCore/SOCKSProxyClient.h @@ -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(); } diff --git a/Userland/Libraries/LibCore/Socket.h b/Userland/Libraries/LibCore/Socket.h index 08310046ce..0906b02116 100644 --- a/Userland/Libraries/LibCore/Socket.h +++ b/Userland/Libraries/LibCore/Socket.h @@ -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(); } diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp index 68a47520e5..74482ed7bb 100644 --- a/Userland/Libraries/LibGUI/TextEditor.cpp +++ b/Userland/Libraries/LibGUI/TextEditor.cpp @@ -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(); diff --git a/Userland/Libraries/LibGemini/Job.cpp b/Userland/Libraries/LibGemini/Job.cpp index a7cde0a21f..9cfb6483f0 100644 --- a/Userland/Libraries/LibGemini/Job.cpp +++ b/Userland/Libraries/LibGemini/Job.cpp @@ -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); } diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 4914734ff1..1f308b214e 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -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(); diff --git a/Userland/Libraries/LibIMAP/Client.cpp b/Userland/Libraries/LibIMAP/Client.cpp index 894a4a0dc1..e952e73ca9 100644 --- a/Userland/Libraries/LibIMAP/Client.cpp +++ b/Userland/Libraries/LibIMAP/Client.cpp @@ -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 {}; } diff --git a/Userland/Libraries/LibIPC/Connection.cpp b/Userland/Libraries/LibIPC/Connection.cpp index 1c94f5ad11..b791b5b8d1 100644 --- a/Userland/Libraries/LibIPC/Connection.cpp +++ b/Userland/Libraries/LibIPC/Connection.cpp @@ -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(); diff --git a/Userland/Libraries/LibJS/Console.cpp b/Userland/Libraries/LibJS/Console.cpp index abce1392dc..cc3af07d97 100644 --- a/Userland/Libraries/LibJS/Console.cpp +++ b/Userland/Libraries/LibJS/Console.cpp @@ -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; } diff --git a/Userland/Libraries/LibJS/Print.cpp b/Userland/Libraries/LibJS/Print.cpp index 6400e6abfa..dc0b364550 100644 --- a/Userland/Libraries/LibJS/Print.cpp +++ b/Userland/Libraries/LibJS/Print.cpp @@ -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 {}; } diff --git a/Userland/Libraries/LibLine/InternalFunctions.cpp b/Userland/Libraries/LibLine/InternalFunctions.cpp index 5b137debd7..21991959c6 100644 --- a/Userland/Libraries/LibLine/InternalFunctions.cpp +++ b/Userland/Libraries/LibLine/InternalFunctions.cpp @@ -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); diff --git a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp index 5a51e95183..98833292f0 100644 --- a/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp +++ b/Userland/Libraries/LibLine/XtermSuggestionDisplay.cpp @@ -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)); } diff --git a/Userland/Libraries/LibProtocol/Request.cpp b/Userland/Libraries/LibProtocol/Request.cpp index 930c5e3092..c10b260978 100644 --- a/Userland/Libraries/LibProtocol/Request.cpp +++ b/Userland/Libraries/LibProtocol/Request.cpp @@ -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()) diff --git a/Userland/Libraries/LibSQL/Heap.cpp b/Userland/Libraries/LibSQL/Heap.cpp index 3dff07f800..9888ea7274 100644 --- a/Userland/Libraries/LibSQL/Heap.cpp +++ b/Userland/Libraries/LibSQL/Heap.cpp @@ -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++; diff --git a/Userland/Libraries/LibSQL/SQLClient.cpp b/Userland/Libraries/LibSQL/SQLClient.cpp index 33f21ac3b4..44e11cdd90 100644 --- a/Userland/Libraries/LibSQL/SQLClient.cpp +++ b/Userland/Libraries/LibSQL/SQLClient.cpp @@ -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)); } diff --git a/Userland/Libraries/LibTLS/Socket.cpp b/Userland/Libraries/LibTLS/Socket.cpp index e68d37a4d0..d8d25931d8 100644 --- a/Userland/Libraries/LibTLS/Socket.cpp +++ b/Userland/Libraries/LibTLS/Socket.cpp @@ -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); diff --git a/Userland/Libraries/LibTLS/TLSv12.h b/Userland/Libraries/LibTLS/TLSv12.h index c1241163d9..92649343dd 100644 --- a/Userland/Libraries/LibTLS/TLSv12.h +++ b/Userland/Libraries/LibTLS/TLSv12.h @@ -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()); } diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 107f311524..fd944a90c9 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -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; }; diff --git a/Userland/Libraries/LibWasm/Parser/Parser.cpp b/Userland/Libraries/LibWasm/Parser/Parser.cpp index 68303398ff..35c53be67f 100644 --- a/Userland/Libraries/LibWasm/Parser/Parser.cpp +++ b/Userland/Libraries/LibWasm/Parser/Parser.cpp @@ -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(); diff --git a/Userland/Libraries/LibWasm/Types.h b/Userland/Libraries/LibWasm/Types.h index 6d7d460aca..7d5b330313 100644 --- a/Userland/Libraries/LibWasm/Types.h +++ b/Userland/Libraries/LibWasm/Types.h @@ -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); } diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp index 81d2f2b3a5..99b645bb65 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp @@ -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 {}; diff --git a/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp b/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp index 401e03d921..09d093a615 100644 --- a/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp +++ b/Userland/Libraries/LibWebSocket/Impl/WebSocketImplSerenity.cpp @@ -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()); } |