Do not put AICurlEasyRequest in a container.

This commit is contained in:
Aleric Inglewood
2012-11-12 18:42:55 +01:00
parent 303c74f4c9
commit 155cc56632
3 changed files with 16 additions and 13 deletions

View File

@@ -105,25 +105,24 @@ void PerHostRequestQueue::removed_from_multi_handle(void)
void PerHostRequestQueue::queue(AICurlEasyRequest const& easy_request) 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) bool PerHostRequestQueue::cancel(AICurlEasyRequest const& easy_request)
{ {
std::deque<AICurlEasyRequest>::iterator const end = mQueuedRequests.end(); queued_request_type::iterator const end = mQueuedRequests.end();
std::deque<AICurlEasyRequest>::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request); queued_request_type::iterator cur = std::find(mQueuedRequests.begin(), end, easy_request.get_ptr());
if (cur == end) if (cur == end)
return false; // Not found. return false; // Not found.
// We can't use erase because that uses assignment to move elements, which is // We can't use erase because that uses assignment to move elements,
// private because it isn't thread-safe for AICurlEasyRequest. Therefore, move // because it isn't thread-safe. Therefore, move the element that we found to
// the element that we found to the back with swap (could just swap with the // the back with swap (could just swap with the end immediately, but I don't
// end immediately, but I don't want to break the order in which requests where // want to break the order in which requests where added). Swap is also not
// added). Swap is also not thread-safe, but OK here because it only touches the // thread-safe, but OK here because it only touches the objects in the deque,
// AICurlEasyRequest objects in the deque, and the deque is protected by the // and the deque is protected by the lock on the PerHostRequestQueue object.
// lock on the PerHostRequestQueue object. queued_request_type::iterator prev = cur;
std::deque<AICurlEasyRequest>::iterator prev = cur;
while (++cur != end) while (++cur != end)
{ {
prev->swap(*cur); // This is safe, prev->swap(*cur); // This is safe,

View File

@@ -45,6 +45,10 @@ namespace curlthread { class MultiHandle; }
class PerHostRequestQueue; class PerHostRequestQueue;
class RefCountedThreadSafePerHostRequestQueue; 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. // PerHostRequestQueue objects are created by the curl thread and destructed by the main thread.
// We need locking. // We need locking.
@@ -91,7 +95,7 @@ class PerHostRequestQueue {
static void purge(void); static void purge(void);
private: 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. int mAdded; // Number of active easy handles with this host.
queued_request_type mQueuedRequests; // Waiting (throttled) requests. queued_request_type mQueuedRequests; // Waiting (throttled) requests.

View File

@@ -521,7 +521,7 @@ class ThreadSafeBufferedCurlEasyRequest : public AIThreadSafeSimple<BufferedCurl
}; };
// The curl easy request type wrapped in a reference counting pointer. // 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. // This class wraps CURLM*'s.
// It guarantees that a pointer is cleaned up when no longer needed, as required by libcurl. // It guarantees that a pointer is cleaned up when no longer needed, as required by libcurl.