Remove release_back_to_server

This commit is contained in:
2025-09-12 19:43:39 -04:00
parent e887906da8
commit e96a493835
10 changed files with 295 additions and 342 deletions

View File

@@ -243,19 +243,19 @@ CommitRequest {
#### Connection Ownership Lifecycle
1. **Creation**: Accept threads create connections, transfer to epoll as raw pointers
1. **Processing**: Network threads claim ownership by wrapping in unique_ptr
1. **Handler Transfer**: Handlers can take ownership for async processing via unique_ptr.release()
1. **Return Path**: Handlers use Server::release_back_to_server() to return connections
1. **Safety**: All transfers use weak_ptr to server for safe cleanup
1. **Cleanup**: RAII ensures proper resource cleanup in all scenarios
1. **Creation**: Server creates connections and stores them in registry
1. **Processing**: I/O threads access connections via registry lookup
1. **Handler Access**: Handlers receive Connection& references, server retains ownership
1. **Async Processing**: Handlers use WeakRef<Connection> for safe async access
1. **Safety**: Connection mutex synchronizes concurrent access between threads
1. **Cleanup**: RAII ensures proper resource cleanup when connections are destroyed
#### Arena Memory Lifecycle
1. **Request Processing**: Handler uses `conn->get_arena()` to allocate memory for parsing request data
1. **Response Generation**: Handler uses arena for temporary response construction (headers, JSON, etc.)
1. **Response Queuing**: Handler calls `conn->append_message()` which copies data to arena-backed message queue
1. **Response Writing**: Server writes all queued messages to socket via `writeBytes()`
1. **Request Processing**: Handler creates request-scoped arena for parsing request data
1. **Response Generation**: Handler uses same arena for response construction (headers, JSON, etc.)
1. **Response Queuing**: Handler calls `conn->append_message()` passing span + arena ownership
1. **Response Writing**: I/O thread writes messages to socket, arena freed after completion
> **Note**: Call `conn->reset()` periodically to reclaim arena memory. Best practice is after all outgoing bytes have been written.