refactor: Use aliasing shared_ptr in Sock::Wait

This commit is contained in:
MarcoFalke 2026-02-01 17:42:32 +01:00
parent b58eebf152
commit faa016af54
No known key found for this signature in database

View File

@ -138,10 +138,12 @@ bool Sock::IsSelectable() const
bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
{
// We need a `shared_ptr` owning `this` for `WaitMany()`, but don't want
// We need a `shared_ptr` holding `this` for `WaitMany()`, but don't want
// `this` to be destroyed when the `shared_ptr` goes out of scope at the
// end of this function. Create it with a custom noop deleter.
std::shared_ptr<const Sock> shared{this, [](const Sock*) {}};
// end of this function.
// Create it with an aliasing shared_ptr that points to `this` without
// owning it.
std::shared_ptr<const Sock> shared{std::shared_ptr<const Sock>{}, this};
EventsPerSock events_per_sock{std::make_pair(shared, Events{requested})};