From fbbb87d517544e2e5acd9786180cc91d748270d6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 7 Nov 2021 11:38:01 +0100 Subject: [PATCH] DHCPClient: Replace Result use with ErrorOr --- Userland/Services/DHCPClient/DHCPv4Client.cpp | 11 ++++------- Userland/Services/DHCPClient/DHCPv4Client.h | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Userland/Services/DHCPClient/DHCPv4Client.cpp b/Userland/Services/DHCPClient/DHCPv4Client.cpp index 421cf9e4d89..7b9d5f2728b 100644 --- a/Userland/Services/DHCPClient/DHCPv4Client.cpp +++ b/Userland/Services/DHCPClient/DHCPv4Client.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -161,20 +162,16 @@ void DHCPv4Client::try_discover_ifs() } } -Result DHCPv4Client::get_discoverable_interfaces() +ErrorOr DHCPv4Client::get_discoverable_interfaces() { - auto file = Core::File::construct("/proc/net/adapters"); - if (!file->open(Core::OpenMode::ReadOnly)) { - dbgln("Error: Failed to open /proc/net/adapters: {}", file->error_string()); - return String { file->error_string() }; - } + auto file = TRY(Core::File::open("/proc/net/adapters", Core::OpenMode::ReadOnly)); auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); if (!json.has_value() || !json.value().is_array()) { dbgln("Error: No network adapters available"); - return String { "No network adapters available" }; + return Error::from_string_literal("No network adapters available"sv); } Vector ifnames_to_immediately_discover, ifnames_to_attempt_later; diff --git a/Userland/Services/DHCPClient/DHCPv4Client.h b/Userland/Services/DHCPClient/DHCPv4Client.h index cdd5cf7b001..0664b94837b 100644 --- a/Userland/Services/DHCPClient/DHCPv4Client.h +++ b/Userland/Services/DHCPClient/DHCPv4Client.h @@ -7,9 +7,9 @@ #pragma once #include "DHCPv4.h" +#include #include #include -#include #include #include #include @@ -53,7 +53,7 @@ public: Vector ready; Vector not_ready; }; - static Result get_discoverable_interfaces(); + static ErrorOr get_discoverable_interfaces(); private: explicit DHCPv4Client();