EchoServer: Defer removal of client from clients HashMap

This is necessary to avoid trying to destruct the on_ready_to_read
function from inside the function.
This commit is contained in:
Brendan Coles 2021-10-23 11:49:27 +00:00 committed by Andreas Kling
commit 1d03f62444
Notes: sideshowbarker 2024-07-18 02:01:24 +09:00

View file

@ -62,8 +62,10 @@ int main(int argc, char** argv)
auto client = Client::create(id, move(client_socket));
client->on_exit = [&clients, id] {
clients.remove(id);
outln("Client {} disconnected", id);
Core::deferred_invoke([&clients, id] {
clients.remove(id);
outln("Client {} disconnected", id);
});
};
clients.set(id, client);
};