diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index 75a93c0de7..b9ba5f45eb 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -22,6 +22,15 @@ void UDPSocket::for_each(Function callback) }); } +ErrorOr UDPSocket::try_for_each(Function(const UDPSocket&)> callback) +{ + return sockets_by_port().with_shared([&](const auto& sockets) -> ErrorOr { + for (auto& socket : sockets) + TRY(callback(*socket.value)); + return {}; + }); +} + static Singleton>> s_map; MutexProtected>& UDPSocket::sockets_by_port() diff --git a/Kernel/Net/UDPSocket.h b/Kernel/Net/UDPSocket.h index 2e1dcd0496..40bfef5779 100644 --- a/Kernel/Net/UDPSocket.h +++ b/Kernel/Net/UDPSocket.h @@ -19,6 +19,7 @@ public: static RefPtr from_port(u16); static void for_each(Function); + static ErrorOr try_for_each(Function(const UDPSocket&)>); private: explicit UDPSocket(int protocol, NonnullOwnPtr receive_buffer);