Prevent queueing of messages on connection after it will be closed
This commit is contained in:
@@ -109,11 +109,15 @@ struct Connection : MessageSender {
|
||||
*
|
||||
* @param data_parts Span of string_views pointing to arena-allocated data
|
||||
* @param arena Arena that owns all the memory referenced by data_parts
|
||||
* @param close_after_send Whether to close connection after sending
|
||||
* @param close_after_send Whether to close connection after sending all
|
||||
* queued data
|
||||
*
|
||||
* @note Thread Safety: Must be called from I/O thread only.
|
||||
* @note Ordering: Bytes are sent in the order calls are made.
|
||||
* @note The memory referenced by the data_parts span, must outlive @p arena.
|
||||
* @note Close Request: To request connection close without sending data,
|
||||
* pass empty data_parts span with close_after_send=true. This ensures
|
||||
* all previously queued messages are sent before closing.
|
||||
*
|
||||
* Example usage (from ConnectionHandler::on_preprocess_writes):
|
||||
* ```cpp
|
||||
@@ -289,7 +293,6 @@ private:
|
||||
Arena arena; // Owns all the memory (movable)
|
||||
std::span<std::string_view> data_parts; // Points to arena-allocated memory
|
||||
// (mutable for partial writes)
|
||||
bool close_after_send = false; // Close connection after sending
|
||||
};
|
||||
|
||||
// Server is a friend and can access all networking internals
|
||||
@@ -343,7 +346,8 @@ private:
|
||||
// dropped while server accesses existing elements.
|
||||
int64_t outgoing_bytes_queued_{0}; // Counter of queued bytes
|
||||
std::deque<PendingResponse>
|
||||
pending_response_queue_; // Responses awaiting protocol processing
|
||||
pending_response_queue_; // Responses awaiting protocol processing
|
||||
bool close_requested_{false}; // True if close_after_send has been requested
|
||||
// Set to a negative number in `close`
|
||||
int fd_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user