[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/curl_adapter.cpp |
Date: |
Mon, 07 May 2007 09:33:21 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/05/07 09:33:20
Modified files:
. : ChangeLog
libbase : curl_adapter.cpp
Log message:
* libbase/curl_adapter.cpp (fill_cache): avoid aggressive
polling by
taking naps between iterations. "Smart" sleep times are taken
in consideration so we can tweak them.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.3114&r2=1.3115
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/curl_adapter.cpp?cvsroot=gnash&r1=1.30&r2=1.31
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.3114
retrieving revision 1.3115
diff -u -b -r1.3114 -r1.3115
--- ChangeLog 7 May 2007 07:25:06 -0000 1.3114
+++ ChangeLog 7 May 2007 09:33:20 -0000 1.3115
@@ -1,5 +1,11 @@
2007-05-07 Sandro Santilli <address@hidden>
+ * libbase/curl_adapter.cpp (fill_cache): avoid aggressive polling by
+ taking naps between iterations. "Smart" sleep times are taken
+ in consideration so we can tweak them.
+
+2007-05-07 Sandro Santilli <address@hidden>
+
* libbase/LoadThread.{cpp,h}: Make thread usage a compile-time
configuration. Temporarely defaults to NOT using thread till
we fix bug #19811 and general CPU hogs during loading.
Index: libbase/curl_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/curl_adapter.cpp,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -b -r1.30 -r1.31
--- libbase/curl_adapter.cpp 2 May 2007 16:24:12 -0000 1.30
+++ libbase/curl_adapter.cpp 7 May 2007 09:33:20 -0000 1.31
@@ -17,7 +17,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-/* $Id: curl_adapter.cpp,v 1.30 2007/05/02 16:24:12 rsavoye Exp $ */
+/* $Id: curl_adapter.cpp,v 1.31 2007/05/07 09:33:20 strk Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -32,6 +32,7 @@
#include <map>
#include <iostream>
#include <string>
+#include <unistd.h> // for usleep
using namespace std;
@@ -124,6 +125,14 @@
bool seek_to_end();
/// Returns the size of the stream
+ //
+ /// If size of the stream is unknown, 0 is returned.
+ /// In that case you might try calling this function
+ /// again after filling the cache a bit...
+ ///
+ /// Another approach might be filling the cache ourselves
+ /// aiming at obtaining a useful value.
+ ///
long get_stream_size();
private:
@@ -163,9 +172,15 @@
// Current size of cached data
long unsigned _cached;
+ /// Total stream size.
+ //
+ /// This will be 0 until known
+ ///
+ long unsigned _size;
+
// Attempt at filling the cache up to the given size.
// Will call libcurl routines to fetch data.
- void fill_cache(off_t size);
+ void fill_cache(long unsigned size);
// Append sz bytes to the cache
size_t cache(void *from, size_t sz);
@@ -245,13 +260,31 @@
/*private*/
void
-CurlStreamFile::fill_cache(off_t size)
+CurlStreamFile::fill_cache(long unsigned size)
{
#ifdef GNASH_CURL_VERBOSE
fprintf(stderr, "fill_cache(%d) called\n", size);
#endif
+// Disable this when you're convinced the sleeping mechanism is satisfactory
+#define VERBOSE_POLLING_LOOP 1
+
+#if VERBOSE_POLLING_LOOP
+ long unsigned fetchRequested = size-_cached;
+#endif
+
+ // These are the minimum and maximum times in microseconds
+ // to nap between curl_multi_perform calls if the amount
+ // of data requested haven't arrived yet.
+ //
+ const long unsigned minSleep = 500000; // half second
+ const long unsigned maxSleep = 1000000; // one second
+
CURLMcode mcode;
+#if VERBOSE_POLLING_LOOP
+ long unsigned lastCached = _cached;
+#endif
+ long unsigned sleepTime = minSleep;
while (_cached < size && _running)
{
do
@@ -264,6 +297,26 @@
throw gnash::GnashException(curl_multi_strerror(mcode));
}
+ // done...
+ if ( _cached >= size || ! _running ) break;
+
+ // In order to avoid overusing the CPU we take a nap if we
didn't
+ // reach the requested position.
+
+#if VERBOSE_POLLING_LOOP
+ long unsigned fetched = _cached - lastCached;
+
+ fprintf(stderr, "CurlStreamFile %p: Fetched: %lu (%lu/%lu
total) - requested %lu (%lu total) - sleeping %lu milliseconds\n",
+ this, fetched, _cached, get_stream_size(),
fetchRequested, size, sleepTime/1000);
+ lastCached = _cached;
+#endif
+
+ usleep(sleepTime);
+
+ // If we'll need to sleep again we'll sleep more next time...
+ // Up to a max (maxSleep)
+ sleepTime = std::min(sleepTime*2, maxSleep);
+
}
// TODO: check for 404 only once !
@@ -297,6 +350,7 @@
_error = 0;
_cached = 0;
+ _size = 0;
_handle = curl_easy_init();
_mhandle = curl_multi_init();
@@ -528,16 +582,18 @@
long
CurlStreamFile::get_stream_size()
{
+ if ( ! _size )
+ {
double size;
- curl_easy_getinfo(_handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &size);
-
- int ret = static_cast<long>(size);
+ CURLcode ret = curl_easy_getinfo(_handle,
CURLINFO_CONTENT_LENGTH_DOWNLOAD, &size);
+ if ( ret == CURLE_OK ) _size = int(size);
+ }
#ifdef GNASH_CURL_VERBOSE
- fprintf(stderr, "get_stream_size() returning %ld\n", ret);
+ fprintf(stderr, "get_stream_size() returning %lu\n", _size);
#endif
- return ret;
+ return _size;
}