[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/IOChannel.cpp libbase/I...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/IOChannel.cpp libbase/I... |
Date: |
Mon, 09 Jun 2008 17:23:42 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 08/06/09 17:23:42
Modified files:
. : ChangeLog
libbase : IOChannel.cpp IOChannel.h curl_adapter.cpp
Log message:
* libbase/IOChannel.{cpp,h}: docs cleanup, have write_bytes
throw IOException by default (unsupported op).
* libbase/curl_adapter.cpp: implement the Curl adapter by
subclassing IOChannel (get rid of tu_file use in it).
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6868&r2=1.6869
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/IOChannel.cpp?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/IOChannel.h?cvsroot=gnash&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/curl_adapter.cpp?cvsroot=gnash&r1=1.62&r2=1.63
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6868
retrieving revision 1.6869
diff -u -b -r1.6868 -r1.6869
--- ChangeLog 9 Jun 2008 15:36:38 -0000 1.6868
+++ ChangeLog 9 Jun 2008 17:23:39 -0000 1.6869
@@ -1,5 +1,12 @@
2008-06-09 Sandro Santilli <address@hidden>
+ * libbase/IOChannel.{cpp,h}: docs cleanup, have write_bytes
+ throw IOException by default (unsupported op).
+ * libbase/curl_adapter.cpp: implement the Curl adapter by
+ subclassing IOChannel (get rid of tu_file use in it).
+
+2008-06-09 Sandro Santilli <address@hidden>
+
* testsuite/server/StreamTest.cpp: fix build.
2008-06-09 Sandro Santilli <address@hidden>
Index: libbase/IOChannel.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/IOChannel.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libbase/IOChannel.cpp 9 Jun 2008 14:44:48 -0000 1.3
+++ libbase/IOChannel.cpp 9 Jun 2008 17:23:41 -0000 1.4
@@ -141,5 +141,10 @@
write_bytes(&u, 1); // will trhow on error it seems
}
+int
+IOChannel::write_bytes(const void* src, int num)
+{
+ throw IOException("This IOChannel implementation doesn't support
output");
+}
} // namespace gnash
Index: libbase/IOChannel.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/IOChannel.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- libbase/IOChannel.h 9 Jun 2008 14:44:48 -0000 1.3
+++ libbase/IOChannel.h 9 Jun 2008 17:23:41 -0000 1.4
@@ -106,11 +106,11 @@
///
virtual int read_bytes(void* dst, int num)=0;
- /// \brief Write the given number of bytes to the stream
+ /// Write the given number of bytes to the stream
//
- /// Throw IOException on error
+ /// Throw IOException on error/unsupported op.
///
- virtual int write_bytes(const void* src, int num)=0;
+ virtual int write_bytes(const void* src, int num);
/// \brief Write a 0-terminated string to a stream.
//
Index: libbase/curl_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/curl_adapter.cpp,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -b -r1.62 -r1.63
--- libbase/curl_adapter.cpp 9 Jun 2008 14:31:52 -0000 1.62
+++ libbase/curl_adapter.cpp 9 Jun 2008 17:23:41 -0000 1.63
@@ -23,6 +23,7 @@
#endif
#include "tu_file.h"
+#include "IOChannel.h"
#include "curl_adapter.h"
#include "log.h"
#include "WallClockTimer.h"
@@ -344,7 +345,7 @@
*
**********************************************************************/
-class CurlStreamFile
+class CurlStreamFile : public IOChannel
{
public:
@@ -370,24 +371,28 @@
//
/// Return number of actually read bytes
///
- size_t read(void *dst, size_t bytes);
+ virtual int read_bytes(void *dst, int bytes);
/// Return true if EOF has been reached
- bool eof();
+ virtual bool get_eof() const;
+
+ bool eof() const { return get_eof(); }
/// Return the error condition of current stream
- int err() const {
+ virtual int get_error() const {
return _error;
}
/// Report global position within the file
- size_t tell();
+ virtual int get_position() const;
+
+ int tell() const { return get_position(); }
/// Put read pointer at given position
- bool seek(size_t pos);
+ virtual int set_position(int pos);
/// Put read pointer at eof
- bool seek_to_end();
+ virtual void go_to_end();
/// Returns the size of the stream
//
@@ -398,7 +403,7 @@
/// Another approach might be filling the cache ourselves
/// aiming at obtaining a useful value.
///
- long get_stream_size();
+ virtual int get_size() const;
private:
@@ -441,7 +446,7 @@
//
/// This will be 0 until known
///
- long unsigned _size;
+ mutable int _size;
// Attempt at filling the cache up to the given size.
// Will call libcurl routines to fetch data.
@@ -849,10 +854,10 @@
}
/*public*/
-size_t
-CurlStreamFile::read(void *dst, size_t bytes)
+int
+CurlStreamFile::read_bytes(void *dst, int bytes)
{
- if ( eof() || _error ) return 0;
+ if ( get_eof() || _error ) return 0;
#ifdef GNASH_CURL_VERBOSE
gnash::log_debug ("read(%d) called", bytes);
@@ -871,7 +876,7 @@
/*public*/
bool
-CurlStreamFile::eof()
+CurlStreamFile::get_eof() const
{
bool ret = ( ! _running && feof(_cache) );
@@ -883,10 +888,10 @@
}
/*public*/
-size_t
-CurlStreamFile::tell()
+int
+CurlStreamFile::get_position() const
{
- long ret = std::ftell(_cache);
+ int ret = std::ftell(_cache);
#ifdef GNASH_CURL_VERBOSE
gnash::log_debug("tell() returning %ld", ret);
@@ -897,8 +902,8 @@
}
/*public*/
-bool
-CurlStreamFile::seek(size_t pos)
+int
+CurlStreamFile::set_position(int pos)
{
#ifdef GNASH_CURL_WARN_SEEKSBACK
if ( pos < tell() ) {
@@ -908,26 +913,26 @@
#endif
fillCache(pos);
- if ( _error ) return false; // error can be set by fillCache
+ if ( _error ) return -1; // error can be set by fillCache
- if ( _cached < pos )
+ if ( _cached < (unsigned int)pos )
{
gnash::log_error ("Warning: could not cache anough bytes on
seek: %d requested, %d cached", pos, _cached);
- return false; // couldn't cache so many bytes
+ return -1; // couldn't cache so many bytes
}
if (std::fseek(_cache, pos, SEEK_SET) == -1) {
gnash::log_error("Warning: fseek failed");
- return false;
+ return -1;
} else {
- return true;
+ return 0;
}
}
/*public*/
-bool
-CurlStreamFile::seek_to_end()
+void
+CurlStreamFile::go_to_end()
{
CURLMcode mcode;
while (_running > 0)
@@ -939,32 +944,31 @@
if ( mcode != CURLM_OK )
{
- throw gnash::GnashException(curl_multi_strerror(mcode));
+ throw gnash::IOException(curl_multi_strerror(mcode));
}
long code;
curl_easy_getinfo(_handle, CURLINFO_RESPONSE_CODE, &code);
if ( code == 404 ) // file not found!
{
- gnash::log_error(_("404 response from url %s"), _url);
- _error = TU_FILE_OPEN_ERROR;
- return false;
+ throw gnash::IOException("File not found");
+ //gnash::log_error(_("404 response from url %s"),
_url);
+ //_error = TU_FILE_OPEN_ERROR;
+ //return;
}
}
if (std::fseek(_cache, 0, SEEK_END) == -1) {
- gnash::log_error("Warning: fseek to end failed");
- return false;
- } else {
- return true;
+ throw gnash::IOException("curl_adapter: fseek to end failed");
+ //gnash::log_error("Warning: fseek to end failed");
+ //return -1;
}
-
}
/*public*/
-long
-CurlStreamFile::get_stream_size()
+int
+CurlStreamFile::get_size() const
{
if ( ! _size )
{
@@ -1084,84 +1088,6 @@
}
-/***********************************************************************
- *
- * Adapter calls
- *
- **********************************************************************/
-
-
-// Return number of bytes actually read.
-static int
-read(void* dst, int bytes, void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- return stream->read(dst, bytes);
-}
-
-static int
-err(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- return stream->err();
-}
-
-static bool
-eof(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- return stream->eof();
-}
-
-static int
-write(const void* /*src*/, int /*bytes*/, void* /*appdata*/)
-{
- abort(); // not supported
- return 0;
-}
-
-static int
-seek(int pos, void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- if ( stream->seek(pos) ) return 0;
- else return TU_FILE_SEEK_ERROR;
-}
-
-static int
-seek_to_end(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- if ( stream->seek_to_end() ) return 0;
- else return TU_FILE_SEEK_ERROR;
-}
-
-static int
-tell(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- return stream->tell();
-}
-
-static long
-get_stream_size(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
- return stream->get_stream_size();
-
-}
-
-static int
-close(void* appdata)
-{
- CurlStreamFile* stream = (CurlStreamFile*) appdata;
-
- delete stream;
-
- //return TU_FILE_CLOSE_ERROR;
- return 0;
-}
-
//-------------------------------------------
// Exported interfaces
//-------------------------------------------
@@ -1184,17 +1110,7 @@
return NULL;
}
- return new tu_file(
- (void*)stream, // opaque user pointer
- read, // read
- write, // write
- seek, // seek
- seek_to_end, // seek_to_end
- tell, // tell
- eof, // get eof
- err, // get error
- get_stream_size, // size of stream
- close);
+ return stream;
}
IOChannel*
@@ -1215,17 +1131,7 @@
return NULL;
}
- return new tu_file(
- (void*)stream, // opaque user pointer
- read, // read
- write, // write
- seek, // seek
- seek_to_end, // seek_to_end
- tell, // tell
- eof, // get eof
- err, // get error
- get_stream_size, // size of stream
- close);
+ return stream;
}
} // namespace curl_adapter