mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +00:00
Kernel: Add LocalSocket::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
74ab8ccde0
commit
24be52b3f5
2 changed files with 10 additions and 0 deletions
|
@ -34,6 +34,15 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> LocalSocket::try_for_each(Function<ErrorOr<void>(const LocalSocket&)> callback)
|
||||||
|
{
|
||||||
|
return all_sockets().with_shared([&](const auto& sockets) -> ErrorOr<void> {
|
||||||
|
for (auto& socket : sockets)
|
||||||
|
TRY(callback(socket));
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
|
ErrorOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
|
||||||
{
|
{
|
||||||
auto client_buffer = TRY(DoubleBuffer::try_create());
|
auto client_buffer = TRY(DoubleBuffer::try_create());
|
||||||
|
|
|
@ -30,6 +30,7 @@ public:
|
||||||
ErrorOr<NonnullRefPtr<OpenFileDescription>> recvfd(const OpenFileDescription& socket_description);
|
ErrorOr<NonnullRefPtr<OpenFileDescription>> recvfd(const OpenFileDescription& socket_description);
|
||||||
|
|
||||||
static void for_each(Function<void(const LocalSocket&)>);
|
static void for_each(Function<void(const LocalSocket&)>);
|
||||||
|
static ErrorOr<void> try_for_each(Function<ErrorOr<void>(const LocalSocket&)>);
|
||||||
|
|
||||||
StringView socket_path() const;
|
StringView socket_path() const;
|
||||||
ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription& description) const override;
|
ErrorOr<NonnullOwnPtr<KString>> pseudo_path(const OpenFileDescription& description) const override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue