gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash extensions/fileio/fileio.h extensions/fil...


From: Udo Giacomozzi
Subject: [Gnash-commit] gnash extensions/fileio/fileio.h extensions/fil...
Date: Sat, 22 Dec 2007 18:28:18 +0000

CVSROOT:        /cvsroot/gnash
Module name:    gnash
Changes by:     Udo Giacomozzi <udog>   07/12/22 18:28:17

Modified files:
        extensions/fileio: fileio.h fileio.cpp 
        .              : ChangeLog 

Log message:
        extensions/fileio/fileio.{h,cpp}: Implement asyncmode() so that the 
extension can be used with device drivers. Fix fgetc() to return a valid string.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/fileio/fileio.h?cvsroot=gnash&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/gnash/extensions/fileio/fileio.cpp?cvsroot=gnash&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5242&r2=1.5243

Patches:
Index: extensions/fileio/fileio.h
===================================================================
RCS file: /cvsroot/gnash/gnash/extensions/fileio/fileio.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- extensions/fileio/fileio.h  27 Nov 2007 09:03:18 -0000      1.8
+++ extensions/fileio/fileio.h  22 Dec 2007 18:28:17 -0000      1.9
@@ -52,6 +52,7 @@
     int fseek(long offset);
     int fseek(long offset, int whence);
     long ftell();
+    bool asyncmode(bool async); 
     bool feof();
     bool unlink(const std::string &filespec);
     void scandir(const std::string& dir, as_value* result);    

Index: extensions/fileio/fileio.cpp
===================================================================
RCS file: /cvsroot/gnash/gnash/extensions/fileio/fileio.cpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- extensions/fileio/fileio.cpp        27 Nov 2007 09:03:18 -0000      1.18
+++ extensions/fileio/fileio.cpp        22 Dec 2007 18:28:17 -0000      1.19
@@ -27,6 +27,7 @@
 
 #include <dirent.h> // used by scandir()
 #include <unistd.h> // used by unlink()
+#include <fcntl.h>  // used by asyncmode()
 
 #include "VM.h"
 #include "log.h"
@@ -60,6 +61,7 @@
 as_value fileio_feof(const fn_call& fn);
 as_value fileio_fseek(const fn_call& fn);
 as_value fileio_unlink(const fn_call& fn);
+as_value fileio_asyncmode(const fn_call& fn);
 
 // <Udo> I needed a scandir() function and implemented it here for simplicity.
 // Maybe this should be moved to a dedicated extension and a different class? 
@@ -92,6 +94,7 @@
     obj.init_member("fflush", new builtin_function(fileio_fflush));
     obj.init_member("fseek", new builtin_function(fileio_fseek));
     obj.init_member("ftell", new builtin_function(fileio_ftell));
+    obj.init_member("asyncmode", new builtin_function(fileio_asyncmode));
     obj.init_member("feof", new builtin_function(fileio_feof));
     obj.init_member("fclose", new builtin_function(fileio_fclose));
     
@@ -194,6 +197,28 @@
 }
 
 bool
+Fileio::asyncmode(bool async)
+{
+//    GNASH_REPORT_FUNCTION;
+    if (_stream) {
+    
+        int fd = fileno(_stream);
+        
+        long flags = fcntl(fd, F_GETFL);
+        
+        int res;
+    
+        if (async)
+          res = fcntl(fd, F_SETFL, flags|O_NONBLOCK);
+        else
+          res = fcntl(fd, F_SETFL, flags&(~O_NONBLOCK));
+          
+        return res>=0;
+    }
+    return false;
+}
+
+bool
 Fileio::feof()
 {
 //    GNASH_REPORT_FUNCTION;
@@ -395,8 +420,15 @@
     boost::intrusive_ptr<Fileio> ptr = ensureType<Fileio>(fn.this_ptr);
     assert(ptr);
     int i = ptr->fgetc();
-    char *c = reinterpret_cast<char *>(&i);
+    
+    if ((i==EOF) || (i<0)) 
+    {
+      return as_value(false);  // possible in async mode
+    } else {
+      char c[2]="x"; // set to 1 char to get the zero byte!
+      c[0] = i;
     return as_value(c);
+    }
 }
 
 as_value
@@ -513,6 +545,16 @@
 }
 
 as_value
+fileio_asyncmode(const fn_call& fn)
+{
+//    GNASH_REPORT_FUNCTION;
+    boost::intrusive_ptr<Fileio> ptr = ensureType<Fileio>(fn.this_ptr);
+    assert(ptr);
+    bool b = (bool) fn.arg(0).to_bool();
+    return as_value(ptr->asyncmode(b));
+}
+
+as_value
 fileio_feof(const fn_call& fn)
 {
 //    GNASH_REPORT_FUNCTION;

Index: ChangeLog
===================================================================
RCS file: /cvsroot/gnash/gnash/ChangeLog,v
retrieving revision 1.5242
retrieving revision 1.5243
diff -u -b -r1.5242 -r1.5243
--- ChangeLog   21 Dec 2007 23:39:14 -0000      1.5242
+++ ChangeLog   22 Dec 2007 18:28:17 -0000      1.5243
@@ -1,3 +1,9 @@
+2007-12-21 Udo Giacomozzi <address@hidden>
+
+       * extensions/fileio/fileio.{h,cpp}: Implement asyncmode() so that the
+         extension can be used with device drivers. Fix fgetc() to return
+         a valid string.
+
 2007-12-21 Sandro Santilli <address@hidden>
 
        * testsuite/misc-ming.all/: DragDropTest.as,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]