diff --git a/indra/llmessage/aicurlperservice.cpp b/indra/llmessage/aicurlperservice.cpp index 6f6047bae..4c503e517 100644 --- a/indra/llmessage/aicurlperservice.cpp +++ b/indra/llmessage/aicurlperservice.cpp @@ -301,10 +301,17 @@ void AIPerService::removed_from_multi_handle(AICapabilityType capability_type, b --mTotalAdded; } -void AIPerService::queue(AICurlEasyRequest const& easy_request, AICapabilityType capability_type) +// Returns true if the request was queued. +bool AIPerService::queue(AICurlEasyRequest const& easy_request, AICapabilityType capability_type, bool force_queuing) { - mCapabilityType[capability_type].mQueuedRequests.push_back(easy_request.get_ptr()); - TotalQueued_wat(sTotalQueued)->count++; + CapabilityType::queued_request_type& queued_requests(mCapabilityType[capability_type].mQueuedRequests); + bool needs_queuing = force_queuing || !queued_requests.empty(); + if (needs_queuing) + { + queued_requests.push_back(easy_request.get_ptr()); + TotalQueued_wat(sTotalQueued)->count++; + } + return needs_queuing; } bool AIPerService::cancel(AICurlEasyRequest const& easy_request, AICapabilityType capability_type) diff --git a/indra/llmessage/aicurlperservice.h b/indra/llmessage/aicurlperservice.h index 13673f19c..bd399b6e9 100644 --- a/indra/llmessage/aicurlperservice.h +++ b/indra/llmessage/aicurlperservice.h @@ -218,8 +218,8 @@ class AIPerService { void download_started(AICapabilityType capability_type) { ++mCapabilityType[capability_type].mDownloading; } bool throttled(void) const; // Returns true if the maximum number of allowed requests for this service have been added to the multi handle. - void queue(AICurlEasyRequest const& easy_request, AICapabilityType capability_type); // Add easy_request to the queue. - bool cancel(AICurlEasyRequest const& easy_request, AICapabilityType capability_type); // Remove easy_request from the queue (if it's there). + bool queue(AICurlEasyRequest const& easy_request, AICapabilityType capability_type, bool force_queuing = true); // Add easy_request to the queue if queue is empty or force_queuing. + bool cancel(AICurlEasyRequest const& easy_request, AICapabilityType capability_type); // Remove easy_request from the queue (if it's there). void add_queued_to(AICurlPrivate::curlthread::MultiHandle* mh, bool recursive = false); // Add queued easy handle (if any) to the multi handle. The request is removed from the queue, diff --git a/indra/llmessage/aicurlthread.cpp b/indra/llmessage/aicurlthread.cpp index 6ede742b8..e16ae7e3a 100644 --- a/indra/llmessage/aicurlthread.cpp +++ b/indra/llmessage/aicurlthread.cpp @@ -1721,6 +1721,19 @@ bool MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request, bool f AICurlEasyRequest_wat curl_easy_request_w(*easy_request); capability_type = curl_easy_request_w->capability_type(); per_service = curl_easy_request_w->getPerServicePtr(); + if (!from_queue) + { + // Add the request to the back of a non-empty queue. + if (PerService_wat(*per_service)->queue(easy_request, capability_type, false)) + { + // The queue was not empty, therefore the request was queued. +#ifdef SHOW_ASSERT + // Not active yet, but it's no longer an error if next we try to remove the request. + curl_easy_request_w->mRemovedPerCommand = false; +#endif + return true; + } + } bool too_much_bandwidth = !curl_easy_request_w->approved() && AIPerService::checkBandwidthUsage(per_service, get_clock_count() * HTTPTimeout::sClockWidth_40ms); PerService_wat per_service_w(*per_service); if (!too_much_bandwidth && sTotalAdded < curl_max_total_concurrent_connections && !per_service_w->throttled())