mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:17:45 +00:00
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:
parent
1d5b45f7d9
commit
d5871f5717
109 changed files with 474 additions and 329 deletions
|
@ -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 {};
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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(); }
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()); }
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 {};
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue