1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

Everywhere: Remove unintentional partial stream reads and writes

This commit is contained in:
Tim Schumacher 2023-03-01 17:24:50 +01:00 committed by Linus Groh
parent 26516ee160
commit ae51c1821c
44 changed files with 109 additions and 192 deletions

View file

@ -40,8 +40,7 @@ ErrorOr<void> Client::drain_socket()
break;
}
// FIXME: This should write the entire span.
TRY(m_socket->write_some(bytes_read));
TRY(m_socket->write_until_depleted(bytes_read));
}
return {};

View file

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

View file

@ -26,9 +26,8 @@ InspectableProcess::InspectableProcess(pid_t pid, NonnullOwnPtr<Core::LocalSocke
MUST(m_socket->set_blocking(true));
m_socket->on_ready_to_read = [this] {
char c;
// FIXME: This should read the entire span.
[[maybe_unused]] auto buffer = m_socket->read_some({ &c, 1 });
[[maybe_unused]] auto c = m_socket->read_value<char>().release_value_but_fixme_should_propagate_errors();
if (m_socket->is_eof()) {
Core::deferred_invoke([pid = this->m_pid] { g_processes.remove(pid); });
return;
@ -44,14 +43,7 @@ DeprecatedString InspectableProcess::wait_for_response()
return {};
}
u32 length {};
// FIXME: This should read the entire span.
auto length_bytes_read = m_socket->read_some({ (u8*)&length, sizeof(length) }).release_value_but_fixme_should_propagate_errors();
if (length_bytes_read.size() != sizeof(length)) {
dbgln("InspectableProcess got malformed data: PID {}", m_pid);
m_socket->close();
return {};
}
auto length = m_socket->read_value<u32>().release_value_but_fixme_should_propagate_errors();
auto data_buffer = ByteBuffer::create_uninitialized(length).release_value_but_fixme_should_propagate_errors();
auto remaining_data_buffer = data_buffer.bytes();
@ -82,9 +74,8 @@ void InspectableProcess::send_request(JsonObject const& request)
u32 length = serialized.length();
// FIXME: Propagate errors
// FIXME: This should write the entire span.
MUST(m_socket->write_some({ (u8 const*)&length, sizeof(length) }));
MUST(m_socket->write_some(serialized.bytes()));
MUST(m_socket->write_value(length));
MUST(m_socket->write_until_depleted(serialized.bytes()));
}
}

View file

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

View file

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

View file

@ -192,8 +192,7 @@ ErrorOr<void> Client::send_response(Stream& response, HTTP::HttpRequest const& r
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
TRY(m_socket->write_until_depleted(builder_contents));
log_response(200, request);
char buffer[PAGE_SIZE];
@ -235,8 +234,7 @@ ErrorOr<void> Client::send_redirect(StringView redirect_path, HTTP::HttpRequest
builder.append("\r\n"sv);
auto builder_contents = TRY(builder.to_byte_buffer());
// FIXME: This should write the entire span.
TRY(m_socket->write_some(builder_contents));
TRY(m_socket->write_until_depleted(builder_contents));
log_response(301, request);
return {};
@ -365,9 +363,8 @@ ErrorOr<void> Client::send_error_response(unsigned code, HTTP::HttpRequest const
header_builder.append("Content-Type: text/html; charset=UTF-8\r\n"sv);
header_builder.appendff("Content-Length: {}\r\n", content_builder.length());
header_builder.append("\r\n"sv);
// 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())));
TRY(m_socket->write_until_depleted(TRY(header_builder.to_byte_buffer())));
TRY(m_socket->write_until_depleted(TRY(content_builder.to_byte_buffer())));
log_response(code, request);
return {};