diff --git a/src/connection.cpp b/src/connection.cpp index 8f5d0fe..1e2915e 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -132,10 +132,8 @@ void Connection::send_response(void *protocol_context, pending_response_queue_.emplace_back( PendingResponse{protocol_context, response_json, std::move(arena)}); - // Mark that we have pending responses and trigger epoll interest - if (!has_pending_responses_) { - has_pending_responses_ = true; - + // Trigger epoll interest if this is the first pending response + if (pending_response_queue_.size() == 1) { auto server = server_.lock(); if (fd_ >= 0 && server) { // Add EPOLLOUT interest to trigger on_preprocess_writes diff --git a/src/connection.hpp b/src/connection.hpp index d288f62..3fb9308 100644 --- a/src/connection.hpp +++ b/src/connection.hpp @@ -342,8 +342,6 @@ private: // mutex_, but if non-empty mutex_ can be // dropped while server accesses existing elements. 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 pending_response_queue_; // Responses awaiting protocol processing // Set to a negative number in `close` diff --git a/src/server.cpp b/src/server.cpp index 3b37658..f3c1f36 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -438,14 +438,13 @@ void Server::process_connection_writes(Ref &conn, int events) { // Process pending responses first if this is an EPOLLOUT event if (events & EPOLLOUT) { std::unique_lock lock(conn->mutex_); - if (conn->has_pending_responses_) { + if (!conn->pending_response_queue_.empty()) { std::vector pending_vec; pending_vec.reserve(conn->pending_response_queue_.size()); for (auto &response : conn->pending_response_queue_) { pending_vec.push_back(std::move(response)); } conn->pending_response_queue_.clear(); - conn->has_pending_responses_ = false; lock.unlock(); handler_.on_preprocess_writes(*conn, std::span{pending_vec});