Do not put AICurlEasyRequest in a container.
This commit is contained in:
@@ -105,25 +105,24 @@ void PerHostRequestQueue::removed_from_multi_handle(void)
|
||||
|
||||
void PerHostRequestQueue::queue(AICurlEasyRequest const& easy_request)
|
||||
{
|
||||
mQueuedRequests.push_back(easy_request);
|
||||
mQueuedRequests.push_back(easy_request.get_ptr());
|
||||
}
|
||||
|
||||
bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request)
|
||||
{
|
||||
std::deque<AICurlEasyRequest>::iterator const end = mQueuedRequests.end();
|
||||
std::deque<AICurlEasyRequest>::iterator cur = std::find(mQueuedRequests.begin(), end, 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, which is
|
||||
// private because it isn't thread-safe for AICurlEasyRequest. 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
|
||||
// AICurlEasyRequest objects in the deque, and the deque is protected by the
|
||||
// lock on the PerHostRequestQueue object.
|
||||
std::deque<AICurlEasyRequest>::iterator prev = cur;
|
||||
// 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,
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace curlthread { class MultiHandle; }
|
||||
|
||||
class PerHostRequestQueue;
|
||||
class RefCountedThreadSafePerHostRequestQueue;
|
||||
class ThreadSafeBufferedCurlEasyRequest;
|
||||
|
||||
// Forward declaration of BufferedCurlEasyRequestPtr (see aicurlprivate.h).
|
||||
typedef boost::intrusive_ptr<ThreadSafeBufferedCurlEasyRequest> BufferedCurlEasyRequestPtr;
|
||||
|
||||
// PerHostRequestQueue objects are created by the curl thread and destructed by the main thread.
|
||||
// We need locking.
|
||||
@@ -91,7 +95,7 @@ class PerHostRequestQueue {
|
||||
static void purge(void);
|
||||
|
||||
private:
|
||||
typedef std::deque<AICurlEasyRequest> queued_request_type;
|
||||
typedef std::deque<BufferedCurlEasyRequestPtr> queued_request_type;
|
||||
|
||||
int mAdded; // Number of active easy handles with this host.
|
||||
queued_request_type mQueuedRequests; // Waiting (throttled) requests.
|
||||
|
||||
@@ -521,7 +521,7 @@ class ThreadSafeBufferedCurlEasyRequest : public AIThreadSafeSimple<BufferedCurl
|
||||
};
|
||||
|
||||
// The curl easy request type wrapped in a reference counting pointer.
|
||||
typedef boost::intrusive_ptr<AICurlPrivate::ThreadSafeBufferedCurlEasyRequest> BufferedCurlEasyRequestPtr;
|
||||
typedef boost::intrusive_ptr<ThreadSafeBufferedCurlEasyRequest> BufferedCurlEasyRequestPtr;
|
||||
|
||||
// This class wraps CURLM*'s.
|
||||
// It guarantees that a pointer is cleaned up when no longer needed, as required by libcurl.
|
||||
|
||||
Reference in New Issue
Block a user