This commit is contained in:
2025-09-15 10:28:17 -04:00
parent ec2ad27e33
commit 1b220d0d1c
8 changed files with 479 additions and 193 deletions

View File

@@ -3,9 +3,22 @@
#include <span>
#include <string_view>
// Forward declaration to avoid circular dependency
// Forward declarations to avoid circular dependency
struct Connection;
// Include Arena header since PendingResponse uses Arena by value
#include "arena.hpp"
/**
* Represents a response queued by pipeline threads for protocol processing.
* Contains JSON response data that can be wrapped by any protocol.
*/
struct PendingResponse {
void *protocol_context; // Arena-allocated protocol-specific context
std::string_view response_json; // JSON response body (arena-allocated)
Arena arena; // Arena containing response data and context
};
/**
* Abstract interface for handling connection data processing.
*
@@ -89,4 +102,20 @@ public:
* @note Called from this connection's io thread.
*/
virtual void on_batch_complete(std::span<Connection *const> /*batch*/) {}
/**
* Called before processing outgoing writes on a connection.
*
* This hook allows protocol handlers to process queued responses
* before actual socket writes occur. Used for response ordering,
* serialization, and other preprocessing.
*
* @param conn Connection about to write data
* @param pending_responses Responses queued by pipeline threads
* @note Called from this connection's io thread.
* @note Called when EPOLLOUT event occurs
*/
virtual void
on_preprocess_writes(Connection &conn,
std::span<PendingResponse> pending_responses) {}
};