mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 18:55:07 +00:00
Kernel: Add NetworkingManagement::try_for_each() for fallible iteration
This API will allow users to short circuit iteration and properly propagate errors.
This commit is contained in:
parent
da5d678f2a
commit
74ab8ccde0
2 changed files with 10 additions and 0 deletions
|
@ -50,6 +50,15 @@ void NetworkingManagement::for_each(Function<void(NetworkAdapter&)> callback)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> NetworkingManagement::try_for_each(Function<ErrorOr<void>(NetworkAdapter&)> callback)
|
||||||
|
{
|
||||||
|
return m_adapters.with([&](auto& adapters) -> ErrorOr<void> {
|
||||||
|
for (auto& adapter : adapters)
|
||||||
|
TRY(callback(adapter));
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<NetworkAdapter> NetworkingManagement::from_ipv4_address(IPv4Address const& address) const
|
RefPtr<NetworkAdapter> NetworkingManagement::from_ipv4_address(IPv4Address const& address) const
|
||||||
{
|
{
|
||||||
if (address[0] == 0 && address[1] == 0 && address[2] == 0 && address[3] == 0)
|
if (address[0] == 0 && address[1] == 0 && address[2] == 0 && address[3] == 0)
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
NetworkingManagement();
|
NetworkingManagement();
|
||||||
|
|
||||||
void for_each(Function<void(NetworkAdapter&)>);
|
void for_each(Function<void(NetworkAdapter&)>);
|
||||||
|
ErrorOr<void> try_for_each(Function<ErrorOr<void>(NetworkAdapter&)>);
|
||||||
|
|
||||||
RefPtr<NetworkAdapter> from_ipv4_address(const IPv4Address&) const;
|
RefPtr<NetworkAdapter> from_ipv4_address(const IPv4Address&) const;
|
||||||
RefPtr<NetworkAdapter> lookup_by_name(StringView) const;
|
RefPtr<NetworkAdapter> lookup_by_name(StringView) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue