Simplify connection registry
This commit is contained in:
@@ -15,14 +15,6 @@ class Connection;
|
||||
* allocate a large virtual address space efficiently, with physical memory
|
||||
* allocated on-demand as connections are created.
|
||||
*
|
||||
* CRITICAL ORDERING REQUIREMENT:
|
||||
* All connection cleanup MUST follow this exact sequence:
|
||||
* 1. Remove from registry: auto conn = registry.remove(fd)
|
||||
* 2. Delete the connection: unique_ptr destructor handles it automatically
|
||||
*
|
||||
* This ordering prevents race conditions between cleanup and fd reuse.
|
||||
* The unique_ptr interface ensures ownership is always clear and prevents
|
||||
* double-delete bugs.
|
||||
*/
|
||||
class ConnectionRegistry {
|
||||
public:
|
||||
@@ -48,14 +40,6 @@ public:
|
||||
*/
|
||||
void store(int fd, std::unique_ptr<Connection> connection);
|
||||
|
||||
/**
|
||||
* Check if a connection exists in the registry by file descriptor.
|
||||
*
|
||||
* @param fd File descriptor
|
||||
* @return true if connection exists, false otherwise
|
||||
*/
|
||||
bool has(int fd) const;
|
||||
|
||||
/**
|
||||
* Remove a connection from the registry and transfer ownership to caller.
|
||||
* This transfers ownership via unique_ptr move semantics.
|
||||
@@ -72,15 +56,6 @@ public:
|
||||
*/
|
||||
size_t max_fds() const { return max_fds_; }
|
||||
|
||||
/**
|
||||
* Perform graceful shutdown cleanup.
|
||||
* Iterates through all registry entries and cleans up any remaining
|
||||
* connections using the critical ordering: remove -> close -> delete.
|
||||
*
|
||||
* This method is called during server shutdown to ensure no connections leak.
|
||||
*/
|
||||
virtual void shutdown_cleanup();
|
||||
|
||||
// Non-copyable and non-movable
|
||||
ConnectionRegistry(const ConnectionRegistry &) = delete;
|
||||
ConnectionRegistry &operator=(const ConnectionRegistry &) = delete;
|
||||
@@ -90,4 +65,5 @@ public:
|
||||
private:
|
||||
Connection **connections_; ///< mmap'd array of raw connection pointers
|
||||
size_t max_fds_; ///< Maximum file descriptor limit
|
||||
};
|
||||
size_t aligned_size_; ///< Page-aligned size for munmap
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user