// Returns true if the request was queued.
bool AIPerService::queue(AICurlEasyRequest const& easy_request, AICapabilityType capability_type, bool force_queuing)
{
    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());
        if (is_approved(capability_type))
        {
            TotalQueued_wat(sTotalQueued)->approved++;
        }
    }
    return needs_queuing;
}
bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request)
{
    queued_request_type::iterator const end = mQueuedRequests.end();
    queued_request_type::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request.get_ptr());

    if (cur == end)
        return false;		// Not found.

    // We can't use erase because that uses assignment to move elements,
    // because it isn't thread-safe. Therefore, move the element that we found to
    // the back with swap (could just swap with the end immediately, but I don't
    // want to break the order in which requests where added). Swap is also not
    // thread-safe, but OK here because it only touches the objects in the deque,
    // and the deque is protected by the lock on the PerHostRequestQueue object.
    queued_request_type::iterator prev = cur;
    while (++cur != end)
    {
        prev->swap(*cur);				// This is safe,
        prev = cur;
    }
    mQueuedRequests.pop_back();		// if this is safe.
    return true;
}
void PerHostRequestQueue::queue(AICurlEasyRequest const& easy_request)
{
    mQueuedRequests.push_back(easy_request.get_ptr());
}
bool AIPerService::cancel(AICurlEasyRequest const& easy_request, AICapabilityType capability_type)
{
    CapabilityType::queued_request_type::iterator const end = mCapabilityType[capability_type].mQueuedRequests.end();
    CapabilityType::queued_request_type::iterator cur = std::find(mCapabilityType[capability_type].mQueuedRequests.begin(), end, easy_request.get_ptr());

    if (cur == end)
        return false;		// Not found.

    // We can't use erase because that uses assignment to move elements,
    // because it isn't thread-safe. Therefore, move the element that we found to
    // the back with swap (could just swap with the end immediately, but I don't
    // want to break the order in which requests where added). Swap is also not
    // thread-safe, but OK here because it only touches the objects in the deque,
    // and the deque is protected by the lock on the AIPerService object.
    CapabilityType::queued_request_type::iterator prev = cur;
    while (++cur != end)
    {
        prev->swap(*cur);				// This is safe,
        prev = cur;
    }
    mCapabilityType[capability_type].mQueuedRequests.pop_back();		// if this is safe.
    if (is_approved(capability_type))
    {
        TotalQueued_wat total_queued_w(sTotalQueued);
        llassert(total_queued_w->approved > 0);
        total_queued_w->approved--;
    }
    return true;
}