Drop disconnected members from chat rooms

C++ · C++ · intermediate · modification

Clients that hang up stay listed in their rooms until they send `/leave`, which they never do once their socket is gone. This PR adds `Room::prune_disconnected()` (declared in `src/chat/room.hpp`, implemented in `src/chat/room.cpp`): it collects the nicks of members whose connection is closed, removes each one with the existing `leave`, then announces `* NICK left` to the members who are still there and returns how many it removed. `src/chat/server.cpp` calls it on every room at the start of the once-a-second `Server::sweep()`, ahead of the existing step that drops empty rooms. `tests/room_test.cpp` (new) adds unit tests for `prune_disconnected`.

C++20, standard library only, built with CMake (unchanged: it builds `src/chat/*.cpp` into the server and every `tests/*_test.cpp` together with `tests/check_main.cpp` into the test runner) by Apple clang 17 locally and GCC 13 in CI, with `-Wall -Wextra -Wconversion -Werror`. The chat server runs a single-threaded event loop: `Room` and `Server` are used only on that thread, and a connection's `is_open()` changes only while the loop handles socket events, never during a call into `Room` or `Server`. Existing and unchanged: `chat::Connection` (`src/chat/connection.hpp`) is an abstract socket wrapper with `bool is_open() const noexcept` and `void send(std::string_view line) noexcept`, which queues a line and is a no-op on a closed connection. `Room` keeps its members in a `std::vector<Member>` in join order (`Member` is a nick and a `std::shared_ptr<Connection>`), at most 500 per room; `join` refuses a null connection and a nick already in the room, so nicks are unique within a room and every stored connection is non-null. `Server` (`src/chat/server.hpp`, unchanged) owns the rooms in a `std::map<std::string, Room, std::less<>>`. `tests/check.hpp` is the repo's tiny test helper: `TEST(name) { ... }` registers a test, `CHECK(expr)` and `CHECK_EQ(a, b)` record a failure with file and line, and the `main` in `tests/check_main.cpp` runs every registered test and exits non-zero if any check failed. `tests/fake_connection.hpp` (existing) provides `FakeConnection`, which records every line sent while open and has `close()`.

Requirements

Files touched

Review this PR

C++ practice