mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 11:57:36 +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
|
@ -31,7 +31,7 @@ ErrorOr<void> Client::drain_socket()
|
|||
auto buffer = TRY(ByteBuffer::create_uninitialized(1024));
|
||||
|
||||
while (TRY(m_socket->can_read_without_blocking())) {
|
||||
auto bytes_read = TRY(m_socket->read(buffer));
|
||||
auto bytes_read = TRY(m_socket->read_some(buffer));
|
||||
|
||||
dbgln("Read {} bytes.", bytes_read.size());
|
||||
|
||||
|
@ -40,7 +40,8 @@ ErrorOr<void> Client::drain_socket()
|
|||
break;
|
||||
}
|
||||
|
||||
TRY(m_socket->write(bytes_read));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some(bytes_read));
|
||||
}
|
||||
|
||||
return {};
|
||||
|
|
|
@ -237,10 +237,11 @@ ErrorOr<int> execute_work_items(Vector<WorkItem> const& items)
|
|||
|
||||
while (true) {
|
||||
print_progress();
|
||||
auto bytes_read = TRY(source_file->read(buffer.bytes()));
|
||||
auto bytes_read = TRY(source_file->read_some(buffer.bytes()));
|
||||
if (bytes_read.is_empty())
|
||||
break;
|
||||
if (auto result = destination_file->write(bytes_read); result.is_error()) {
|
||||
// FIXME: This should write the entire span.
|
||||
if (auto result = destination_file->write_some(bytes_read); result.is_error()) {
|
||||
// FIXME: Return the formatted string directly. There is no way to do this right now without the temporary going out of scope and being destroyed.
|
||||
report_warning(DeprecatedString::formatted("Failed to write to destination file: {}", result.error()));
|
||||
return result.release_error();
|
||||
|
|
|
@ -27,7 +27,8 @@ InspectableProcess::InspectableProcess(pid_t pid, NonnullOwnPtr<Core::LocalSocke
|
|||
|
||||
m_socket->on_ready_to_read = [this] {
|
||||
char c;
|
||||
[[maybe_unused]] auto buffer = m_socket->read({ &c, 1 });
|
||||
// FIXME: This should read the entire span.
|
||||
[[maybe_unused]] auto buffer = m_socket->read_some({ &c, 1 });
|
||||
if (m_socket->is_eof()) {
|
||||
Core::deferred_invoke([pid = this->m_pid] { g_processes.remove(pid); });
|
||||
return;
|
||||
|
@ -44,7 +45,8 @@ DeprecatedString InspectableProcess::wait_for_response()
|
|||
}
|
||||
|
||||
u32 length {};
|
||||
auto length_bytes_read = m_socket->read({ (u8*)&length, sizeof(length) }).release_value_but_fixme_should_propagate_errors();
|
||||
// FIXME: This should read the entire span.
|
||||
auto length_bytes_read = m_socket->read_some({ (u8*)&length, sizeof(length) }).release_value_but_fixme_should_propagate_errors();
|
||||
if (length_bytes_read.size() != sizeof(length)) {
|
||||
dbgln("InspectableProcess got malformed data: PID {}", m_pid);
|
||||
m_socket->close();
|
||||
|
@ -55,7 +57,7 @@ DeprecatedString InspectableProcess::wait_for_response()
|
|||
auto remaining_data_buffer = data_buffer.bytes();
|
||||
|
||||
while (!remaining_data_buffer.is_empty()) {
|
||||
auto maybe_bytes_read = m_socket->read(remaining_data_buffer);
|
||||
auto maybe_bytes_read = m_socket->read_some(remaining_data_buffer);
|
||||
if (maybe_bytes_read.is_error()) {
|
||||
dbgln("InspectableProcess::wait_for_response: Failed to read data: {}", maybe_bytes_read.error());
|
||||
break;
|
||||
|
@ -80,8 +82,9 @@ void InspectableProcess::send_request(JsonObject const& request)
|
|||
u32 length = serialized.length();
|
||||
|
||||
// FIXME: Propagate errors
|
||||
MUST(m_socket->write({ (u8 const*)&length, sizeof(length) }));
|
||||
MUST(m_socket->write(serialized.bytes()));
|
||||
// FIXME: This should write the entire span.
|
||||
MUST(m_socket->write_some({ (u8 const*)&length, sizeof(length) }));
|
||||
MUST(m_socket->write_some(serialized.bytes()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -239,10 +239,11 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, DeprecatedString
|
|||
auto udp_socket = TRY(Core::UDPSocket::connect(nameserver, 53, Time::from_seconds(1)));
|
||||
TRY(udp_socket->set_blocking(true));
|
||||
|
||||
TRY(udp_socket->write(buffer));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(udp_socket->write_some(buffer));
|
||||
|
||||
u8 response_buffer[4096];
|
||||
int nrecv = TRY(udp_socket->read({ response_buffer, sizeof(response_buffer) })).size();
|
||||
int nrecv = TRY(udp_socket->read_some({ response_buffer, sizeof(response_buffer) })).size();
|
||||
if (udp_socket->is_eof())
|
||||
return Vector<Answer> {};
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ ErrorOr<void> Client::drain_socket()
|
|||
auto buffer = TRY(ByteBuffer::create_uninitialized(1024));
|
||||
|
||||
while (TRY(m_socket->can_read_without_blocking())) {
|
||||
auto read_bytes = TRY(m_socket->read(buffer));
|
||||
auto read_bytes = TRY(m_socket->read_some(buffer));
|
||||
|
||||
m_parser.write(StringView { read_bytes });
|
||||
|
||||
|
@ -161,7 +161,8 @@ ErrorOr<void> Client::send_data(StringView data)
|
|||
}
|
||||
|
||||
if (fast) {
|
||||
TRY(m_socket->write({ data.characters_without_null_termination(), data.length() }));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some({ data.characters_without_null_termination(), data.length() }));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -183,7 +184,8 @@ ErrorOr<void> Client::send_data(StringView data)
|
|||
}
|
||||
|
||||
auto builder_contents = TRY(builder.to_byte_buffer());
|
||||
TRY(m_socket->write(builder_contents));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some(builder_contents));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -204,7 +206,8 @@ ErrorOr<void> Client::send_commands(Vector<Command> commands)
|
|||
}
|
||||
|
||||
VERIFY(TRY(stream.tell()) == buffer.size());
|
||||
TRY(m_socket->write({ buffer.data(), buffer.size() }));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some({ buffer.data(), buffer.size() }));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
|
@ -192,18 +192,19 @@ ErrorOr<void> Client::send_response(Stream& response, HTTP::HttpRequest const& r
|
|||
builder.append("\r\n"sv);
|
||||
|
||||
auto builder_contents = TRY(builder.to_byte_buffer());
|
||||
TRY(m_socket->write(builder_contents));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some(builder_contents));
|
||||
log_response(200, request);
|
||||
|
||||
char buffer[PAGE_SIZE];
|
||||
do {
|
||||
auto size = TRY(response.read({ buffer, sizeof(buffer) })).size();
|
||||
auto size = TRY(response.read_some({ buffer, sizeof(buffer) })).size();
|
||||
if (response.is_eof() && size == 0)
|
||||
break;
|
||||
|
||||
ReadonlyBytes write_buffer { buffer, size };
|
||||
while (!write_buffer.is_empty()) {
|
||||
auto nwritten = TRY(m_socket->write(write_buffer));
|
||||
auto nwritten = TRY(m_socket->write_some(write_buffer));
|
||||
|
||||
if (nwritten == 0) {
|
||||
dbgln("EEEEEE got 0 bytes written!");
|
||||
|
@ -234,7 +235,8 @@ ErrorOr<void> Client::send_redirect(StringView redirect_path, HTTP::HttpRequest
|
|||
builder.append("\r\n"sv);
|
||||
|
||||
auto builder_contents = TRY(builder.to_byte_buffer());
|
||||
TRY(m_socket->write(builder_contents));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some(builder_contents));
|
||||
|
||||
log_response(301, request);
|
||||
return {};
|
||||
|
@ -363,8 +365,9 @@ ErrorOr<void> Client::send_error_response(unsigned code, HTTP::HttpRequest const
|
|||
header_builder.append("Content-Type: text/html; charset=UTF-8\r\n"sv);
|
||||
header_builder.appendff("Content-Length: {}\r\n", content_builder.length());
|
||||
header_builder.append("\r\n"sv);
|
||||
TRY(m_socket->write(TRY(header_builder.to_byte_buffer())));
|
||||
TRY(m_socket->write(TRY(content_builder.to_byte_buffer())));
|
||||
// FIXME: This should write the entire span.
|
||||
TRY(m_socket->write_some(TRY(header_builder.to_byte_buffer())));
|
||||
TRY(m_socket->write_some(TRY(content_builder.to_byte_buffer())));
|
||||
|
||||
log_response(code, request);
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue