diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index de46196624..57b811637a 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -34,6 +34,15 @@ void LocalSocket::for_each(Function callback) }); } +ErrorOr LocalSocket::try_for_each(Function(const LocalSocket&)> callback) +{ + return all_sockets().with_shared([&](const auto& sockets) -> ErrorOr { + for (auto& socket : sockets) + TRY(callback(socket)); + return {}; + }); +} + ErrorOr> LocalSocket::try_create(int type) { auto client_buffer = TRY(DoubleBuffer::try_create()); diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index c9643f7310..4bc5c3e4a3 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -30,6 +30,7 @@ public: ErrorOr> recvfd(const OpenFileDescription& socket_description); static void for_each(Function); + static ErrorOr try_for_each(Function(const LocalSocket&)>); StringView socket_path() const; ErrorOr> pseudo_path(const OpenFileDescription& description) const override;