Finish std::shared_ptr -> Ref migration

This commit is contained in:
2025-09-11 15:06:04 -04:00
parent a2da7fba84
commit 0561d951d4
5 changed files with 34 additions and 24 deletions

View File

@@ -29,18 +29,18 @@
*
* IMPORTANT: Server uses a factory pattern and MUST be created via
* Server::create(). This ensures:
* - Proper shared_ptr semantics for enable_shared_from_this
* - Safe weak_ptr references from Connection objects
* - Proper Ref<Server> semantics for reference counting
* - Safe WeakRef<Server> references from Connection objects
* - Prevention of accidental stack allocation that would break safety
* guarantees
*/
struct Server : std::enable_shared_from_this<Server> {
struct Server {
/**
* Factory method to create a Server instance.
*
* This is the only way to create a Server - ensures proper shared_ptr
* This is the only way to create a Server - ensures proper Ref<Server>
* semantics and prevents accidental stack allocation that would break
* weak_ptr safety.
* WeakRef<Server> safety.
*
* @param config Server configuration (threads, ports, limits, etc.)
* @param handler Protocol handler for processing connection data
@@ -48,11 +48,11 @@ struct Server : std::enable_shared_from_this<Server> {
* Server takes ownership and will close them on
* destruction. Server will set these to non-blocking mode for safe epoll
* usage. Empty vector means no listening sockets.
* @return shared_ptr to the newly created Server
* @return Ref to the newly created Server
*/
static std::shared_ptr<Server> create(const weaseldb::Config &config,
ConnectionHandler &handler,
const std::vector<int> &listen_fds);
static Ref<Server> create(const weaseldb::Config &config,
ConnectionHandler &handler,
const std::vector<int> &listen_fds);
/**
* Destructor ensures proper cleanup of all resources.
@@ -122,6 +122,10 @@ private:
*/
explicit Server(const weaseldb::Config &config, ConnectionHandler &handler,
const std::vector<int> &listen_fds);
friend Ref<Server> make_ref<Server>(const weaseldb::Config &config,
ConnectionHandler &handler,
const std::vector<int> &listen_fds);
WeakRef<Server> self_;
const weaseldb::Config &config_;
ConnectionHandler &handler_;