Remove has_pending_responses_

This commit is contained in:
2025-09-15 11:10:47 -04:00
parent 1b220d0d1c
commit 1cb7a4c301
3 changed files with 3 additions and 8 deletions

View File

@@ -132,10 +132,8 @@ void Connection::send_response(void *protocol_context,
pending_response_queue_.emplace_back( pending_response_queue_.emplace_back(
PendingResponse{protocol_context, response_json, std::move(arena)}); PendingResponse{protocol_context, response_json, std::move(arena)});
// Mark that we have pending responses and trigger epoll interest // Trigger epoll interest if this is the first pending response
if (!has_pending_responses_) { if (pending_response_queue_.size() == 1) {
has_pending_responses_ = true;
auto server = server_.lock(); auto server = server_.lock();
if (fd_ >= 0 && server) { if (fd_ >= 0 && server) {
// Add EPOLLOUT interest to trigger on_preprocess_writes // Add EPOLLOUT interest to trigger on_preprocess_writes

View File

@@ -342,8 +342,6 @@ private:
// mutex_, but if non-empty mutex_ can be // mutex_, but if non-empty mutex_ can be
// dropped while server accesses existing elements. // dropped while server accesses existing elements.
int64_t outgoing_bytes_queued_{0}; // Counter of queued bytes int64_t outgoing_bytes_queued_{0}; // Counter of queued bytes
bool has_pending_responses_{
false}; // True if protocol handler has responses to process
std::deque<PendingResponse> std::deque<PendingResponse>
pending_response_queue_; // Responses awaiting protocol processing pending_response_queue_; // Responses awaiting protocol processing
// Set to a negative number in `close` // Set to a negative number in `close`

View File

@@ -438,14 +438,13 @@ void Server::process_connection_writes(Ref<Connection> &conn, int events) {
// Process pending responses first if this is an EPOLLOUT event // Process pending responses first if this is an EPOLLOUT event
if (events & EPOLLOUT) { if (events & EPOLLOUT) {
std::unique_lock lock(conn->mutex_); std::unique_lock lock(conn->mutex_);
if (conn->has_pending_responses_) { if (!conn->pending_response_queue_.empty()) {
std::vector<PendingResponse> pending_vec; std::vector<PendingResponse> pending_vec;
pending_vec.reserve(conn->pending_response_queue_.size()); pending_vec.reserve(conn->pending_response_queue_.size());
for (auto &response : conn->pending_response_queue_) { for (auto &response : conn->pending_response_queue_) {
pending_vec.push_back(std::move(response)); pending_vec.push_back(std::move(response));
} }
conn->pending_response_queue_.clear(); conn->pending_response_queue_.clear();
conn->has_pending_responses_ = false;
lock.unlock(); lock.unlock();
handler_.on_preprocess_writes(*conn, std::span{pending_vec}); handler_.on_preprocess_writes(*conn, std::span{pending_vec});