netstat: Port to Core::Stream

This commit is contained in:
Sam Atkins 2022-09-14 16:57:17 +01:00 committed by Linus Groh
parent b5f4e96e71
commit c8b3e68c6e
Notes: sideshowbarker 2024-07-17 04:15:45 +09:00

View File

@ -11,8 +11,8 @@
#include <AK/QuickSort.h>
#include <AK/String.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCore/ProcessStatisticsReader.h>
#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
#include <arpa/inet.h>
@ -154,13 +154,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (!has_protocol_flag || flag_tcp) {
auto file = Core::File::construct("/sys/kernel/net/tcp");
if (!file->open(Core::OpenMode::ReadOnly)) {
warnln("Error: {}", file->error_string());
return 1;
}
auto file_contents = file->read_all();
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/tcp"sv, Core::Stream::OpenMode::Read));
auto file_contents = TRY(file->read_all());
auto json_or_error = JsonValue::from_string(file_contents);
if (json_or_error.is_error()) {
warnln("Error: {}", json_or_error.error());
@ -251,8 +246,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}
if (!has_protocol_flag || flag_udp) {
auto file = TRY(Core::File::open("/sys/kernel/net/udp", Core::OpenMode::ReadOnly));
auto file_contents = file->read_all();
auto file = TRY(Core::Stream::File::open("/sys/kernel/net/udp"sv, Core::Stream::OpenMode::Read));
auto file_contents = TRY(file->read_all());
auto json = TRY(JsonValue::from_string(file_contents));
Vector<JsonValue> sorted_regions = json.as_array().values();