+2007-12-09 Luca Bruno <lethalman88@gmail.com>
+
+ Reviewed by Alp Toker.
+
+ http://bugs.webkit.org/show_bug.cgi?id=15825
+ [GTK] curl - slow dns causing hangs.
+
+ Create a vector of jobs, to satisfy requests in the right order.
+ Set a limit to the number of simultaneous connections.
+
+ * platform/network/curl/ResourceHandleManager.cpp:
+ (WebCore::maxRunningJobs): added
+ (WebCore::ResourceHandleManager::ResourceHandleManager):
+ (WebCore::ResourceHandleManager::removeFromCurl):
+ (WebCore::ResourceHandleManager::startScheduledJobs):
+
+ * platform/network/curl/ResourceHandleManager.h:
+ (WebCore::ResourceHandleList): removed
+ (WebCore::ResourceHandleManager::m_runningJobs): added
+ (WebCore::ResourceHandleManager::m_resourceHandleListHead): removed
+ (WebCore::ResourceHandleManager::m_resourceHandleList): added
+
2007-12-08 Sam Weinig <sam@webkit.org>
Reviewed by Oliver.
const int selectTimeoutMS = 5;
const double pollTimeSeconds = 0.05;
+const int maxRunningJobs = 5;
ResourceHandleManager::ResourceHandleManager()
: m_downloadTimer(this, &ResourceHandleManager::downloadTimerCallback)
, m_cookieJarFileName(0)
- , m_resourceHandleListHead(0)
+ , m_runningJobs(0)
{
curl_global_init(CURL_GLOBAL_ALL);
m_curlMultiHandle = curl_multi_init();
ASSERT(d->m_handle);
if (!d->m_handle)
return;
+ m_runningJobs--;
curl_multi_remove_handle(m_curlMultiHandle, d->m_handle);
curl_easy_cleanup(d->m_handle);
d->m_handle = 0;
{
// we can be called from within curl, so to avoid re-entrancy issues
// schedule this job to be added the next time we enter curl download loop
- m_resourceHandleListHead = new ResourceHandleList(job, m_resourceHandleListHead);
+ m_resourceHandleList.append(job);
if (!m_downloadTimer.isActive())
m_downloadTimer.startOneShot(pollTimeSeconds);
}
bool ResourceHandleManager::removeScheduledJob(ResourceHandle* job)
{
- ResourceHandleList* node = m_resourceHandleListHead;
- while (node) {
- ResourceHandleList* next = node->next();
- if (job == node->job()) {
- node->setRemoved(true);
+ int size = m_resourceHandleList.size();
+ for (int i=0; i < size; i++) {
+ if (job == m_resourceHandleList[i]) {
+ m_resourceHandleList.remove(i);
return true;
}
- node = next;
}
return false;
}
bool ResourceHandleManager::startScheduledJobs()
{
+ // TODO: Create a separate stack of jobs for each domain.
+
bool started = false;
- ResourceHandleList* node = m_resourceHandleListHead;
- while (node) {
- ResourceHandleList* next = node->next();
- if (!node->removed()) {
- startJob(node->job());
- started = true;
- }
- delete node;
- node = next;
+ while (!m_resourceHandleList.isEmpty() && m_runningJobs < maxRunningJobs) {
+ ResourceHandle* job = m_resourceHandleList[0];
+ startJob(job);
+ m_resourceHandleList.remove(0);
+ started = true;
}
- m_resourceHandleListHead = 0;
return started;
}
else if ("HEAD" == job->request().httpMethod())
curl_easy_setopt(d->m_handle, CURLOPT_NOBODY, TRUE);
+ m_runningJobs++;
CURLMcode ret = curl_multi_add_handle(m_curlMultiHandle, d->m_handle);
// don't call perform, because events must be async
// timeout will occur and do curl_multi_perform
if (removeScheduledJob(job))
return;
removeFromCurl(job);
- // FIXME: report an error?
}
} // namespace WebCore
#include "Frame.h"
#include "Timer.h"
#include "ResourceHandleClient.h"
+
#include <curl/curl.h>
+#include <wtf/Vector.h>
namespace WebCore {
-class ResourceHandleList {
-public:
- ResourceHandleList(ResourceHandle* job, ResourceHandleList* next)
- : m_job(job)
- , m_next(next)
- , m_removed(false)
- {}
- ResourceHandleList* next() const { return m_next; }
- ResourceHandle* job() const { return m_job; }
- void setRemoved(bool removed) { m_removed = removed; }
- bool removed() const { return m_removed; }
-
-private:
- ResourceHandle* m_job;
- ResourceHandleList* m_next;
- bool m_removed;
-};
-
class ResourceHandleManager {
public:
static ResourceHandleManager* sharedInstance();
CURLSH* m_curlShareHandle;
char* m_cookieJarFileName;
char m_curlErrorBuffer[CURL_ERROR_SIZE];
- ResourceHandleList* m_resourceHandleListHead;
+ Vector<ResourceHandle*> m_resourceHandleList;
+ int m_runningJobs;
};
}