Add on_write_progress

This commit is contained in:
2025-08-19 14:23:17 -04:00
parent c95aecfe8c
commit ecfb7f3307
6 changed files with 42 additions and 14 deletions

View File

@@ -105,7 +105,6 @@ See `config.md` for complete configuration documentation.
- **Safe shutdown mechanism** with async-signal-safe shutdown() method
- **Connection ownership management** with automatic cleanup on server destruction
- **Pluggable protocol handlers** via ConnectionHandler interface
- TODO design a way to stream server sent events
Key features:
- Multi-threaded architecture: separate accept and network thread pools
@@ -135,7 +134,7 @@ Key features:
- **Connection lifecycle hooks** for initialization and cleanup
Key features:
- process_data() with unique_ptr<Connection>& for ownership transfer
- on_data_arrived()/on_write_progress() with unique_ptr<Connection>& for ownership transfer
- on_connection_established/closed() hooks for protocol state management
- Zero-copy data processing with arena allocator integration
- Thread-safe ownership transfer via Server::releaseBackToServer()
@@ -282,7 +281,7 @@ The modular design allows each component to be optimized independently while mai
### Adding New Protocol Handlers
- Inherit from `ConnectionHandler` in `src/connection_handler.hpp`
- Implement `process_data()` with proper ownership semantics
- Implement `on_data_arrived()` with proper ownership semantics
- Use connection's arena allocator for temporary allocations: `conn->getArena()`
- Handle partial messages and streaming protocols appropriately
- Use `Server::releaseBackToServer()` if taking ownership for async processing
@@ -338,7 +337,7 @@ auto server = Server::create(config, handler);
```cpp
class HttpHandler : public ConnectionHandler {
public:
void process_data(std::string_view data, std::unique_ptr<Connection>& conn_ptr) override {
void on_data_arrived(std::string_view data, std::unique_ptr<Connection>& conn_ptr) override {
// Parse HTTP request using connection's arena
ArenaAllocator& arena = conn_ptr->getArena();
@@ -354,7 +353,7 @@ public:
```cpp
class AsyncHandler : public ConnectionHandler {
public:
void process_data(std::string_view data, std::unique_ptr<Connection>& conn_ptr) override {
void on_data_arrived(std::string_view data, std::unique_ptr<Connection>& conn_ptr) override {
// Take ownership for async processing
auto connection = std::move(conn_ptr); // conn_ptr is now null
@@ -369,6 +368,8 @@ public:
};
```
TODO add example of streaming data
### Arena-Based String Handling
```cpp
// Preferred: Zero-copy string view with arena allocation