gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv...


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/asobj/xmlsocket.cpp serv...
Date: Tue, 03 Apr 2007 16:17:45 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  07/04/03 16:17:45

Modified files:
        .              : ChangeLog 
        server/asobj   : xmlsocket.cpp xmlsocket.h 

Log message:
                * server/asobj/xmlsocket.{cpp,h}: more cleanups and fix for
                  polling from the socket.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2764&r2=1.2765
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.cpp?cvsroot=gnash&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.h?cvsroot=gnash&r1=1.7&r2=1.8

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2764
retrieving revision 1.2765
diff -u -b -r1.2764 -r1.2765
--- ChangeLog   3 Apr 2007 15:24:11 -0000       1.2764
+++ ChangeLog   3 Apr 2007 16:17:44 -0000       1.2765
@@ -1,5 +1,7 @@
 2007-04-03 Sandro Santilli <address@hidden>
 
+       * server/asobj/xmlsocket.{cpp,h}: more cleanups and fix for
+         polling from the socket.
        * libbase/network.{cpp,h}: do not allow assignment, cleanup
          accessor functions to return by const refs.
        * server/asobj/xmlsocket.{cpp,h}: do not override inherited

Index: server/asobj/xmlsocket.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- server/asobj/xmlsocket.cpp  3 Apr 2007 15:24:11 -0000       1.16
+++ server/asobj/xmlsocket.cpp  3 Apr 2007 16:17:45 -0000       1.17
@@ -50,6 +50,8 @@
 # include <sys/select.h>
 #endif
 
+#include <boost/algorithm/string/case_conv.hpp>
+
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN 256
 #endif
@@ -87,7 +89,19 @@
                 as_object(getXMLSocketInterface())
         {}
 
+               /// This function should be called everytime we're willing
+               /// to check if any data is available on the socket.
+               //
+               /// The method will take care of polling from the
+               /// socket and invoking any onData handler.
+               ///
+               void checkForIncomingData(as_environment& env);
+
         XMLSocket obj;
+
+               /// Return the as_function with given name, converting case if 
needed
+               boost::intrusive_ptr<as_function> getEventHandler(const 
std::string& name);
+
 };
 
   
@@ -135,7 +149,7 @@
 
 // Return true if there is data in the socket, otherwise return false.
 bool
-XMLSocket::anydata(char **msgs)
+XMLSocket::anydata(MessageList& msgs)
 {
     //GNASH_REPORT_FUNCTION;
     assert(connected());
@@ -158,7 +172,7 @@
 }
 
 bool
-XMLSocket::anydata(int fd, char **msgs)
+XMLSocket::anydata(int fd, MessageList& msgs)
 {
     GNASH_REPORT_FUNCTION;
 
@@ -175,13 +189,10 @@
     
     
     if (fd <= 0) {
-           log_msg("fd <= 0, returning false");
-           assert(!connected());
+       log_msg("fd <= 0, returning false (timer not unregistered while socket 
disconnected?");
         return false;
     }
     
-    //msgs = (char **)realloc(msgs, sizeof(char *));
-    
     while (retries-- > 0) {
         FD_ZERO(&fdset);
         FD_SET(fd, &fdset);
@@ -210,7 +221,7 @@
         if (ret > 0) {
             log_msg("%s: There is data in the socket for fd #%d!",
                 __FUNCTION__, fd);
-            break;
+            //break;
         }
         memset(buf, 0, INBUF);
         ret = ::read(_sockfd, buf, INBUF-2);
@@ -219,7 +230,8 @@
         //log_msg("%s: read (%d,%d) %s\n", __FUNCTION__, buf[0], buf[1], buf);
         ptr = buf;
         // If we get a single XML message, do less work
-        if (ret == cr + 1) {
+        if (ret == cr + 1)
+               {
             adjusted_size = memadjust(ret + 1);
             packet = new char[adjusted_size];
             printf("Packet size is %d at %p\n", ret + 1, packet);
@@ -229,9 +241,7 @@
             if (eom) {
                 *eom = 0;
             }
-            //data.push_back(packet);
-            msgs[index] = packet;
-            msgs[index+1] = 0;
+            msgs.push_back( packet );
             printf("%d: Pushing Packet of size %d at %p\n", __LINE__, 
strlen(packet), packet);
             processing(false);
             return true;
@@ -273,7 +283,7 @@
                 }
                 //printf("Allocating new packet at %p\n", packet);
                 //data.push_back(packet);
-                msgs[index++] = packet;
+                msgs.push_back( std::string(packet) );
             } else {
                 log_error("Throwing out partial packet %s\n", packet);
             }
@@ -425,12 +435,13 @@
     // confirm this is that onConnect is invoked *after* 
     // XMLSocket.connect() returned in these cases.
     //
-    if (fn.this_ptr->get_member("onConnect", &method))
+       boost::intrusive_ptr<as_function> handler = 
ptr->getEventHandler("onConnect");
+    if ( handler )
     {
         log_msg("XMLSocket.connect(): calling onConnect");
         as_environment env;
         env.push(success);
-        val = call_method(method, &env, ptr.get(), 1, env.stack_size()-1); 
+        val = call_method(handler.get(), &env, ptr.get(), 1, 
env.stack_size()-1); 
     }
            
     if ( success )
@@ -503,10 +514,6 @@
     
     as_value   method;
     as_value   val;
-    as_value      datain;
-    std::vector<const char *> msgs;
-    char          *messages[200];
-    int           i;
     
     boost::intrusive_ptr<xmlsocket_as_object> ptr = 
ensureType<xmlsocket_as_object>(fn.this_ptr);
     if ( ! ptr->obj.connected() )
@@ -515,65 +522,7 @@
            return as_value();
     }
 
-    if (ptr->obj.processingData()) {
-        log_msg("Still processing data!\n");
-        return as_value(false);
-    }
-    
-    memset(messages, 0, sizeof(char *)*200);
-    
-#ifndef USE_DMALLOC
-    //dump_memory_stats(__FUNCTION__, __LINE__, "memory checkpoint");
-#endif
-    
-    assert(ptr->obj.connected());
-
-    if (ptr->obj.anydata(messages))
-    {
-        //log_msg("Got message #%d, %d bytes long at %p: %s", i,
-         //   strlen(messages[i]), messages[i], messages[i]);
-
-        if (fn.this_ptr->get_member("onData", &method))
-        {
-            //log_msg("Got %d messages from XMLsocket", msgs.size());
-            for (i=0; messages[i] != 0; i++)
-            {
-//              log_msg("Got message #%d, %d bytes long at %p: %s: \n", i,
-//                  strlen(messages[i]), messages[i], messages[i]);
-                datain = messages[i];
-                //fn.env().push(datain);
-
-#ifndef USE_DMALLOC
-                //dump_memory_stats(__FUNCTION__, __LINE__, "start");
-#endif
-                as_environment& env = fn.env();
-                env.push(datain);
-                val = call_method(method, &env, fn.this_ptr.get(), 1, 0);
-
-#ifndef USE_DMALLOC
-                //dump_memory_stats(__FUNCTION__, __LINE__, "end");
-#endif  
-                //log_msg("Deleting message #%d at %p\n", i, messages[i]);
-                //delete messages[i];
-                //fn.env().pop();
-                datain.set_undefined();
-            }
-            ptr->obj.processing(false);
-        }
-        else
-        {
-            log_error("Couldn't find onData!");
-        }
-
-        // Delete this in a batch for now so we can track memory allocation
-        for (i=0; messages[i] != 0; i++)
-        {
-            //log_msg("Deleting message #%d at %p\n", i, messages[i]);
-            delete messages[i];
-        }
-    }
-
-    //malloc_trim(0);
+       ptr->checkForIncomingData(fn.env());
   
     return as_value();
 }
@@ -617,6 +566,74 @@
 
 }
 
+boost::intrusive_ptr<as_function>
+xmlsocket_as_object::getEventHandler(const std::string& name)
+{
+               boost::intrusive_ptr<as_function> ret;
+
+               std::string key=name;
+               VM& vm = VM::get();
+               if ( vm.getSWFVersion() < 7 ) boost::to_lower(key, 
vm.getLocale());
+
+               as_value tmp;
+               if ( ! get_member(key, &tmp) ) return ret;
+               ret = tmp.to_as_function();
+               return ret;
+}
+
+void
+xmlsocket_as_object::checkForIncomingData(as_environment& env)
+{
+    assert(obj.connected());
+
+    if (obj.processingData()) {
+        log_msg("Still processing data!");
+    }
+    
+#ifndef USE_DMALLOC
+    //dump_memory_stats(__FUNCTION__, __LINE__, "memory checkpoint");
+#endif
+
+    std::vector<std::string > msgs;
+    if (obj.anydata(msgs))
+    {
+        log_msg("Got %u messages: ", msgs.size());
+               for (size_t i=0; i<msgs.size(); ++i)
+               {
+               log_msg(" Message %u: %s ", i, msgs[i].c_str());
+               }
+
+               boost::intrusive_ptr<as_function> onDataHandler = 
getEventHandler("onData");
+        if ( onDataHandler )
+        {
+            //log_msg("Got %d messages from XMLsocket", msgs.size());
+            for (XMLSocket::MessageList::iterator it=msgs.begin(),
+                                                       itEnd=msgs.end();
+                           it != itEnd; ++it)
+            {
+                               std::string& s = *it;
+                               as_value datain( s );
+
+#ifndef USE_DMALLOC
+                //dump_memory_stats(__FUNCTION__, __LINE__, "start");
+#endif
+                env.push(datain);
+                call_method(as_value(onDataHandler.get()), &env, this, 1, 
env.stack_size()-1);
+
+#ifndef USE_DMALLOC
+                //dump_memory_stats(__FUNCTION__, __LINE__, "end");
+#endif  
+            }
+            obj.processing(false);
+        }
+        else
+        {
+            log_error("Couldn't find onData!");
+        }
+
+    }
+}
+
 } // end of gnash namespace
 
 // Local Variables:

Index: server/asobj/xmlsocket.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- server/asobj/xmlsocket.h    3 Apr 2007 15:24:11 -0000       1.7
+++ server/asobj/xmlsocket.h    3 Apr 2007 16:17:45 -0000       1.8
@@ -41,8 +41,10 @@
     bool send(std::string str);
     void close();
     
-    bool anydata(char **msgs);
-    bool anydata(int sockfd, char **msgs);
+    typedef std::vector<std::string> MessageList;
+
+    bool anydata(MessageList& msgs);
+    bool anydata(int sockfd, MessageList& msgs);
 
     bool fdclosed() { return _closed; }
     bool xmlmsg() { return _xmldata; }
@@ -76,6 +78,7 @@
     bool          _processing;
     std::vector<std::string> _messages;
     //std::vector< boost::intrusive_ptr<as_object> >  _nodes;
+
 };
 
 void xmlsocket_class_init(as_object& global);




reply via email to

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