mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel/Net: Make the LoopbackAdapter initializer to use ErrorOr pattern
This looks much more nice, and also matches our pattern for other types of network adapters' initializers.
This commit is contained in:
parent
9f011592be
commit
bd7d4513bf
Notes:
sideshowbarker
2024-07-17 20:19:08 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/bd7d4513bf Pull-request: https://github.com/SerenityOS/serenity/pull/18282
3 changed files with 6 additions and 9 deletions
|
@ -11,12 +11,10 @@ namespace Kernel {
|
|||
|
||||
static bool s_loopback_initialized = false;
|
||||
|
||||
LockRefPtr<LoopbackAdapter> LoopbackAdapter::try_create()
|
||||
ErrorOr<NonnullRefPtr<LoopbackAdapter>> LoopbackAdapter::try_create()
|
||||
{
|
||||
auto interface_name = KString::try_create("loop"sv);
|
||||
if (interface_name.is_error())
|
||||
return {};
|
||||
return adopt_lock_ref_if_nonnull(new LoopbackAdapter(interface_name.release_value()));
|
||||
auto interface_name = TRY(KString::try_create("loop"sv));
|
||||
return TRY(adopt_nonnull_ref_or_enomem(new (nothrow) LoopbackAdapter(move(interface_name))));
|
||||
}
|
||||
|
||||
LoopbackAdapter::LoopbackAdapter(NonnullOwnPtr<KString> interface_name)
|
||||
|
|
|
@ -15,7 +15,7 @@ private:
|
|||
LoopbackAdapter(NonnullOwnPtr<KString>);
|
||||
|
||||
public:
|
||||
static LockRefPtr<LoopbackAdapter> try_create();
|
||||
static ErrorOr<NonnullRefPtr<LoopbackAdapter>> try_create();
|
||||
virtual ~LoopbackAdapter() override;
|
||||
|
||||
virtual ErrorOr<void> initialize(Badge<NetworkingManagement>) override { VERIFY_NOT_REACHED(); }
|
||||
|
|
|
@ -136,10 +136,9 @@ bool NetworkingManagement::initialize()
|
|||
m_adapters.with([&](auto& adapters) { adapters.append(*result.release_value()); });
|
||||
}));
|
||||
}
|
||||
auto loopback = LoopbackAdapter::try_create();
|
||||
VERIFY(loopback);
|
||||
auto loopback = MUST(LoopbackAdapter::try_create());
|
||||
m_adapters.with([&](auto& adapters) { adapters.append(*loopback); });
|
||||
m_loopback_adapter = loopback;
|
||||
m_loopback_adapter = *loopback;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue