mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-27 06:48:49 +00:00
Kernel: Add TCPSocket::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
24be52b3f5
commit
aabc8d348b
Notes:
sideshowbarker
2024-07-17 18:10:05 +09:00
Author: https://github.com/IdanHo
Commit: aabc8d348b
Pull-request: https://github.com/SerenityOS/serenity/pull/12754
Reviewed-by: https://github.com/bgianfo ✅
Reviewed-by: https://github.com/elcuco
2 changed files with 10 additions and 0 deletions
|
@ -29,6 +29,15 @@ void TCPSocket::for_each(Function<void(const TCPSocket&)> callback)
|
|||
});
|
||||
}
|
||||
|
||||
ErrorOr<void> TCPSocket::try_for_each(Function<ErrorOr<void>(const TCPSocket&)> callback)
|
||||
{
|
||||
return sockets_by_tuple().with_shared([&](const auto& sockets) -> ErrorOr<void> {
|
||||
for (auto& it : sockets)
|
||||
TRY(callback(*it.value));
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
bool TCPSocket::unref() const
|
||||
{
|
||||
bool did_hit_zero = sockets_by_tuple().with_exclusive([&](auto& table) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue