2007-12-09 Luca Bruno <lethalman88@gmail.com>
authoralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Dec 2007 21:52:55 +0000 (21:52 +0000)
committeralp@webkit.org <alp@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Dec 2007 21:52:55 +0000 (21:52 +0000)
        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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28573 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/network/curl/ResourceHandleManager.cpp
WebCore/platform/network/curl/ResourceHandleManager.h

index d0fab9e5a4877c3551c1a72ef24c866bc5005045..d8439f31921c5c0c53c4635eaa1ae49e7e6280ee 100644 (file)
@@ -1,3 +1,25 @@
+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.
index 8f7d243f4b489fd2e2112a8316d7ce9ae0b9c600..936c11446225bf39c6faca2d408803704d88dfac 100644 (file)
@@ -44,11 +44,12 @@ namespace WebCore {
 
 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();
@@ -268,6 +269,7 @@ void ResourceHandleManager::removeFromCurl(ResourceHandle* job)
     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;
@@ -323,39 +325,34 @@ void ResourceHandleManager::add(ResourceHandle* job)
 {
     // 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;
 }
 
@@ -488,6 +485,7 @@ void ResourceHandleManager::startJob(ResourceHandle* job)
     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
@@ -505,7 +503,6 @@ void ResourceHandleManager::cancel(ResourceHandle* job)
     if (removeScheduledJob(job))
         return;
     removeFromCurl(job);
-    // FIXME: report an error?
 }
 
 } // namespace WebCore
index 8cb07676c4ae7a7592d96b215fb684787bdad849..405887af0cd12b030bdc04edbcdacbd4026b7b4d 100644 (file)
 #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();
@@ -77,7 +61,8 @@ private:
     CURLSH* m_curlShareHandle;
     char* m_cookieJarFileName;
     char m_curlErrorBuffer[CURL_ERROR_SIZE];
-    ResourceHandleList* m_resourceHandleListHead;
+    Vector<ResourceHandle*> m_resourceHandleList;
+    int m_runningJobs;
 };
 
 }