gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9641: Reduce XMLSocket code, variou


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9641: Reduce XMLSocket code, various bugfixes and AS compatibility corrections.
Date: Mon, 25 Aug 2008 17:46:59 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9641
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2008-08-25 17:46:59 +0200
message:
  Reduce XMLSocket code, various bugfixes and AS compatibility corrections.
  
  Improve tests.
modified:
  libcore/asobj/LoadVars.cpp
  libcore/asobj/LoadVars.h
  libcore/asobj/XMLSocket_as.cpp
  libcore/asobj/XMLSocket_as.h
  libcore/asobj/xmlnode.cpp
  testsuite/actionscript.all/XMLSocket.as
  testsuite/misc-ming.all/XMLSocketTest.c
    ------------------------------------------------------------
    revno: 9638.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 14:44:06 +0200
    message:
      Use XMLSocket.as to test failed connections. Gnash crashes quite a
      bit (assertion failures).
    modified:
      testsuite/actionscript.all/XMLSocket.as
    ------------------------------------------------------------
    revno: 9638.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 14:45:03 +0200
    message:
      Use to_int() instead of int(to_number()). This may not be correct if a 
      very large number is used (to_int() 'wraps around' to a low number again),
      but at least doesn't overflow an int, which would lead to undefined
      behaviour.
    modified:
      libcore/asobj/xmlnode.cpp
    ------------------------------------------------------------
    revno: 9638.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 14:46:35 +0200
    message:
      Use a single class with multiple inheritance for XMLSocket_as (as_object
      and Network). Drop many unused and useless member functions and data
      members. Don't implement our own mutex; if it turns out to be necessary,
      a proper mutex is better.
      
      Correct the return value of some AS functions.
      
      Don't fail assertions when XMLSocket.close() is called and we aren't 
connected.
    modified:
      libcore/asobj/XMLSocket_as.cpp
      libcore/asobj/XMLSocket_as.h
    ------------------------------------------------------------
    revno: 9638.1.5
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 14:51:27 +0200
    message:
      Check totals.
    modified:
      testsuite/actionscript.all/XMLSocket.as
    ------------------------------------------------------------
    revno: 9638.1.6
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 15:22:17 +0200
    message:
      Close the connection in XMLSocketTest.swf, which can sometimes trigger a 
      test failure in the absence of thread locking.
      
      Add and use a boost::mutex while filling the message list to fix the above
      bug.
      
      Correct the totals in XMLSocket.as.
    modified:
      libcore/asobj/XMLSocket_as.cpp
      libcore/asobj/XMLSocket_as.h
      testsuite/actionscript.all/XMLSocket.as
      testsuite/misc-ming.all/XMLSocketTest.c
    ------------------------------------------------------------
    revno: 9638.1.7
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 15:48:20 +0200
    message:
      Legal header guard, useless escape.
    modified:
      libcore/asobj/LoadVars.cpp
      libcore/asobj/LoadVars.h
    ------------------------------------------------------------
    revno: 9638.1.8
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 15:48:50 +0200
    message:
      Move class definition out of the header.
    modified:
      libcore/asobj/XMLSocket_as.cpp
      libcore/asobj/XMLSocket_as.h
    ------------------------------------------------------------
    revno: 9638.1.9
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Mon 2008-08-25 17:16:42 +0200
    message:
      Trash the mutex, it's unnecessary.
      
      Don't forget to advance the pointer past the C string terminator.
    modified:
      libcore/asobj/XMLSocket_as.cpp
      testsuite/misc-ming.all/XMLSocketTest.c
=== modified file 'libcore/asobj/LoadVars.cpp'
--- a/libcore/asobj/LoadVars.cpp        2008-06-10 06:14:29 +0000
+++ b/libcore/asobj/LoadVars.cpp        2008-08-25 13:48:20 +0000
@@ -364,7 +364,7 @@
 
        if ( startTimer )
        {
-               boost::intrusive_ptr<builtin_function> loadsChecker = \
+               boost::intrusive_ptr<builtin_function> loadsChecker = 
                        new builtin_function(&LoadVars::checkLoads_wrapper);
                std::auto_ptr<Timer> timer(new Timer);
                timer->setInterval(*loadsChecker, 50, this);

=== modified file 'libcore/asobj/LoadVars.h'
--- a/libcore/asobj/LoadVars.h  2008-03-26 21:34:20 +0000
+++ b/libcore/asobj/LoadVars.h  2008-08-25 13:48:20 +0000
@@ -16,10 +16,8 @@
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 //
 
-#ifndef __GNASH_ASOBJ_LOADVARS_H__
-#define __GNASH_ASOBJ_LOADVARS_H__
-
-#include <memory> // for auto_ptr
+#ifndef GNASH_ASOBJ_LOADVARS_H
+#define GNASH_ASOBJ_LOADVARS_H
 
 namespace gnash {
 

=== modified file 'libcore/asobj/XMLSocket_as.cpp'
--- a/libcore/asobj/XMLSocket_as.cpp    2008-08-25 06:59:44 +0000
+++ b/libcore/asobj/XMLSocket_as.cpp    2008-08-25 15:16:42 +0000
@@ -49,8 +49,8 @@
 # include <unistd.h>
 #endif
 
-#include <boost/algorithm/string/case_conv.hpp>
 #include <boost/scoped_array.hpp>
+#include <string>
 
 #define GNASH_XMLSOCKET_DEBUG
 
@@ -63,125 +63,103 @@
 
 // These are the event handlers called for this object
 static as_value xmlsocket_inputChecker(const fn_call& fn);
-
 static as_value xmlsocket_onData(const fn_call& fn);
 
 static as_object* getXMLSocketInterface();
 static void attachXMLSocketInterface(as_object& o);
 static void attachXMLSocketProperties(as_object& o);
 
-class XMLSocket_as : public as_object
-{
+
+class XMLSocket_as : public Network, public as_object {
 
 public:
 
-        XMLSocket_as()
-                :
-                as_object(getXMLSocketInterface())
-        {
-            attachXMLSocketProperties(*this);
-        }
-
-               /// 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();
-
-        XMLSocket obj;
-
-               /// Return the as_function with given name, converting case if 
needed
-               boost::intrusive_ptr<as_function> getEventHandler(const 
std::string& name);
+    typedef std::vector<std::string> MessageList;
+
+    XMLSocket_as();
+    ~XMLSocket_as();
+    
+    bool connect(const std::string& host, short port);
+
+    // Actionscript doesn't care about the result of either of these
+    // operations.
+    void send(std::string str);
+    void close();
+
+       void checkForIncomingData();
+
+private:
+
+    bool fillMessageList(MessageList& msgs);
+
+       /// Return the as_function with given name, converting case if needed
+       boost::intrusive_ptr<as_function> getEventHandler(const std::string& 
name);
+
+    bool _data;
+
+    MessageList _messages;
+
+    std::string _remainder;
 
 };
 
   
-XMLSocket::XMLSocket()
+XMLSocket_as::XMLSocket_as()
     :
-    _data(false),
-    _xmldata(false),
-    _closed(false),
-    _processing(false)
+    as_object(getXMLSocketInterface()),
+    _data(false)
 {
-    GNASH_REPORT_FUNCTION;
+    attachXMLSocketProperties(*this);
 }
 
-XMLSocket::~XMLSocket()
+XMLSocket_as::~XMLSocket_as()
 {
-//    GNASH_REPORT_FUNCTION;
 }
 
 bool
-XMLSocket::connect(const std::string& host, short port)
+XMLSocket_as::connect(const std::string& host, short port)
 {
-    GNASH_REPORT_FUNCTION;
 
     if ( ! URLAccessManager::allowXMLSocket(host, port) )
     {
            return false;
     }
-           
 
     bool success = createClient(host, port);
 
-    assert( success || ! connected() );
+    assert( success || ! _connected );
 
     return success;
 }
 
 void
-XMLSocket::close()
+XMLSocket_as::close()
 {
     GNASH_REPORT_FUNCTION;
 
+    assert(_connected);
+
     closeNet();
     // dunno why Network::closeNet() returns false always
     // doesn't make much sense to me...
     // Anyway, let's make sure we're clean
     assert(!_sockfd);
     assert(!_connected);
-    assert(!connected());
-}
-
-// Return true if there is data in the socket, otherwise return false.
-bool
-XMLSocket::anydata(MessageList& msgs)
-{
-    //GNASH_REPORT_FUNCTION;
-    assert(connected());
-    assert(_sockfd > 0);
-    return anydata(_sockfd, msgs);
-}
-
-bool XMLSocket::processingData()
-{
-    //GNASH_REPORT_FUNCTION;
-    //log_debug(_("%s: processing flag is %d"), __FUNCTION__, _processing);
-    return _processing;
-}
-
-void XMLSocket::processing(bool x)
-{
-    GNASH_REPORT_FUNCTION;
-    //log_debug(_("%s: set processing flag to %d"), __FUNCTION__, x);
-    _processing = x;
-}
-
-bool
-XMLSocket::anydata(int fd, MessageList& msgs)
-{
+}
+
+
+bool
+XMLSocket_as::fillMessageList(MessageList& msgs)
+{
+
+    const int fd = _sockfd;
    
     if (fd <= 0) {
-       log_error(_("%s: fd <= 0, returning false (timer not unregistered while 
socket disconnected?"), __FUNCTION__);
+       log_error(_("%s: fd <= 0, returning false (timer not unregistered "
+               "while socket disconnected?"), __FUNCTION__);
         return false;
     }
 
-
-    //GNASH_REPORT_FUNCTION;
-
-
     fd_set                fdset;
     struct timeval        tval;
     size_t retries = 10;
@@ -219,8 +197,6 @@
             //    __FUNCTION__, fd);
         }
 
-        processing(true);
-
         ret = read(_sockfd, buf.get(), bufSize - 1);
         
         if (buf[ret - 1] != 0)
@@ -246,7 +222,7 @@
             {
                 log_debug ("Adding and clearing remainder");
                 msgs.push_back(_remainder + std::string(ptr));
-                ptr += std::strlen(ptr);
+                ptr += std::strlen(ptr) + 1;
                 _remainder.clear();
                 continue;
             }
@@ -255,7 +231,6 @@
             ptr += std::strlen(ptr) + 1;
         }
         
-        processing(false);
         return true;
         
     }
@@ -263,107 +238,32 @@
     return true;
 }
 
-bool
-XMLSocket::send(std::string str)
+
+// XMLSocket.send doesn't return anything, so we don't need
+// to here either.
+void
+XMLSocket_as::send(std::string str)
 {
-    //GNASH_REPORT_FUNCTION;
-    
-    if ( ! connected() )
+    if (!_connected)
     {
-        log_error(_("%s: socket not initialized"), __FUNCTION__);
-       assert(_sockfd <= 0);
-       return false;
+        log_error(_("XMLSocket.send(): socket not initialized"));
+           assert(_sockfd <= 0);
+           return;
     }
     
     // We have to write the NULL terminator as well.
     int ret = write(_sockfd, str.c_str(), str.size() + 1);
     
-    log_debug(_("%s: sent %d bytes, data was %s"), __FUNCTION__, ret, str);
-    if (ret == static_cast<signed int>(str.size())) {
-        return true;
-    } else {
-        return false;
-    }
-}
-
-// Callbacks
-
-void
-XMLSocket::onClose(std::string /* str */)
-{
-    GNASH_REPORT_FUNCTION;
-}
-
-void
-XMLSocket::onConnect(std::string /* str */)
-{
-    GNASH_REPORT_FUNCTION;
-}
-
-void
-XMLSocket::onData(std::string /* str */)
-{
-    GNASH_REPORT_FUNCTION;
-}
-
-void
-XMLSocket::onXML(std::string /* str */)
-{
-    GNASH_REPORT_FUNCTION;
-}
-
-int
-XMLSocket::checkSockets(void)
-{
-    GNASH_REPORT_FUNCTION;
-    return checkSockets(_sockfd);
-}
-
-int
-XMLSocket::checkSockets(int fd)
-{
-    GNASH_REPORT_FUNCTION;
-    fd_set                fdset;
-    int                   ret = 0;
-    struct timeval        tval;
-    
-
-    FD_ZERO(&fdset);
-    FD_SET(fd, &fdset);
-    
-    tval.tv_sec = 2;
-    tval.tv_usec = 10;
-    
-    ret = ::select(fd+1, &fdset, NULL, NULL, &tval); // &tval
-    
-    // If interupted by a system call, try again
-    if (ret == -1 && errno == EINTR) {
-        log_debug(_("%s: The socket for fd #%d was interupted by a system call 
in this thread"),
-                __FUNCTION__, fd);
-    }
-    if (ret == -1) {
-        log_error(_("%s: The socket for fd #%d never was available"),
-            __FUNCTION__, fd);
-    }
-    if (ret == 0) {
-        log_debug(_("%s: There is no data in the socket for fd #%d"),
-            __FUNCTION__, fd);
-    }
-    if (ret > 0) {
-        log_debug(_("%s: There is data in the socket for fd #%d"),
-            __FUNCTION__, fd);
-    }
-    
-    return ret;
-}
-
+    log_debug(_("XMLSocket.send(): sent %d bytes, data was %s"), ret, str);
+    return;
+}
+
+
+// XMLSocket.connect() returns true if the initial connection was
+// successful, false if no connection was established.
 as_value
 xmlsocket_connect(const fn_call& fn)
 {
-    //GNASH_REPORT_FUNCTION;
-
-    as_value   method;
-    as_value   val;
 
 #ifdef GNASH_XMLSOCKET_DEBUG
     std::stringstream ss;
@@ -373,7 +273,7 @@
 
     boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
 
-    if (ptr->obj.connected())
+    if (ptr->connected())
     {
         log_error(_("XMLSocket.connect() called while already connected, 
ignored"));
     }
@@ -382,7 +282,12 @@
     const std::string& host = hostval.to_string();
     int port = int(fn.arg(1).to_number());
     
-    bool success = ptr->obj.connect(host, port);
+    if (!ptr->connect(host, port))
+    {
+        return as_value(false);
+        // onConnect(false) should not be called here, but rather
+        // only if a failure occurs after the initial connection.
+    }
 
     // Actually, if first-stage connection was successful, we
     // should NOT invoke onConnect(true) here, but postpone
@@ -390,64 +295,74 @@
     // to be done in a separate thread. The visible effect to
     // confirm this is that onConnect is invoked *after* 
     // XMLSocket.connect() returned in these cases.
+    // The same applies to onConnect(false), which will never
+    // be called at the moment.
     //
     log_debug(_("XMLSocket.connect(): tring to call onConnect"));
-    ptr->callMethod(NSV::PROP_ON_CONNECT, success);
+    ptr->callMethod(NSV::PROP_ON_CONNECT, true);
            
-    if ( success )
-    {
-        log_debug(_("Setting up timer for calling XMLSocket.onData()"));
-
-           std::auto_ptr<Timer> timer(new Timer);
-        boost::intrusive_ptr<builtin_function> ondata_handler = new 
builtin_function(&xmlsocket_inputChecker, NULL);
-        unsigned interval = 50; // just make sure it's expired at every frame 
iteration (20 FPS used here)
-        timer->setInterval(*ondata_handler, interval, 
boost::dynamic_pointer_cast<as_object>(ptr));
-
-        VM& vm = ptr->getVM();
-        vm.getRoot().add_interval_timer(timer, true);
-
-        log_debug(_("Timer set"));
-    }
-
-    return as_value(success);
+
+    // This is bad and should be rewritten.
+    log_debug(_("Setting up timer for calling XMLSocket.onData()"));
+
+    std::auto_ptr<Timer> timer(new Timer);
+    boost::intrusive_ptr<builtin_function> ondata_handler = new 
builtin_function(&xmlsocket_inputChecker, NULL);
+    // just make sure it's expired at every frame iteration (20 FPS used here)
+    unsigned interval = 50;
+    timer->setInterval(*ondata_handler, interval, 
boost::dynamic_pointer_cast<as_object>(ptr));
+
+    VM& vm = ptr->getVM();
+    vm.getRoot().add_interval_timer(timer, true);
+
+    log_debug(_("Timer set"));
+
+    return as_value(true);
 }
 
 
+/// XMLSocket.send()
+//
+/// Does not return anything.
 as_value
 xmlsocket_send(const fn_call& fn)
 {
     GNASH_REPORT_FUNCTION;
     
     boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
-    const std::string& object = fn.arg(0).to_string();
-    //  log_debug(_("%s: host=%s, port=%g"), __FUNCTION__, host, port);
-    return as_value(ptr->obj.send(object));
+    const std::string& str = fn.arg(0).to_string();
+    ptr->send(str);
+    return as_value();
 }
 
+
+/// XMLSocket.close()
+//
+/// Always returns void
 as_value
 xmlsocket_close(const fn_call& fn)
 {
     GNASH_REPORT_FUNCTION;
     
     boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
-    // Since the return code from close() doesn't get used by Shockwave,
-    // we don't care either.
-    ptr->obj.close();
+
+    // If we're not connected, there's nothing to do
+    if (!ptr->connected()) return as_value();
+
+    ptr->close();
     return as_value();
 }
 
 as_value
 xmlsocket_new(const fn_call& fn)
 {
-    //GNASH_REPORT_FUNCTION;
-    //log_debug(_("%s: nargs=%d"), __FUNCTION__, nargs);
-    
+
     boost::intrusive_ptr<as_object> xmlsock_obj = new XMLSocket_as;
 
 #ifdef GNASH_XMLSOCKET_DEBUG
     std::stringstream ss;
     fn.dump_args(ss);
-    log_debug(_("new XMLSocket(%s) called - created object at %p"), ss.str(), 
(void*)xmlsock_obj.get());
+    log_debug(_("new XMLSocket(%s) called - created object at "
+            "%p"), ss.str(), static_cast<void*>(xmlsock_obj.get()));
 #else
     UNUSED(fn);
 #endif
@@ -459,13 +374,8 @@
 as_value
 xmlsocket_inputChecker(const fn_call& fn)
 {
-    //GNASH_REPORT_FUNCTION;
-
-    as_value   method;
-    as_value   val;
-    
     boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
-    if ( ! ptr->obj.connected() )
+    if ( ! ptr->connected() )
     {
         log_error(_("%s: not connected"), __FUNCTION__);
         return as_value();
@@ -481,9 +391,7 @@
 {
     GNASH_REPORT_FUNCTION;
 
-    as_value   method;
-    as_value   val;
-    
+   
     boost::intrusive_ptr<XMLSocket_as> ptr = 
ensureType<XMLSocket_as>(fn.this_ptr);
 
     if ( fn.nargs < 1 )
@@ -539,25 +447,22 @@
     onDataIface->init_member(NSV::PROP_CONSTRUCTOR, as_value(onDataFun));
 }
 
-static void
+void
 attachXMLSocketProperties(as_object& /*o*/)
 {
-    // this is attached to proto
-    //o.init_member("onData", new builtin_function(xmlsocket_onData));
+    // Has no own properties
 }
 
 // extern (used by Global.cpp)
 void xmlsocket_class_init(as_object& global)
 {
-//    GNASH_REPORT_FUNCTION;
-    // This is going to be the global XMLSocket "class"/"function"
+    // This is the global XMLSocket class
     static boost::intrusive_ptr<builtin_function> cl;
 
     if ( cl == NULL )
     {
         cl=new builtin_function(&xmlsocket_new, getXMLSocketInterface());
         // Do not replicate all interface to class!
-        //attachXMLSocketInterface(*cl);
     }
     
     // Register _global.String
@@ -580,49 +485,39 @@
 void
 XMLSocket_as::checkForIncomingData()
 {
-    assert(obj.connected());
-
-    if (obj.processingData()) {
-        log_debug(_("Still processing data"));
-    }
+    assert(_connected);
     
     std::vector<std::string> msgs;
-    obj.anydata(msgs);
+    fillMessageList(msgs);
    
-    if (!msgs.empty())
-    {
-        log_debug(_("Got %d messages: "), msgs.size());
-        for (size_t i=0; i<msgs.size(); ++i)
-        {
-            log_debug(_(" Message %d: %s "), i, msgs[i]);
-        }
-
-        boost::intrusive_ptr<as_function> onDataHandler = 
getEventHandler("onData");
-        if ( onDataHandler )
-        {
-            //log_debug(_("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 );
-
-                               as_environment env;
-                               env.push(datain);
-                               fn_call call(this, &env, 1, env.stack_size() - 
1);
-                               onDataHandler->call(call);
-//                call_method(as_value(onDataHandler.get()), &env, this, 1, 
env.stack_size()-1);
-
-            }
-            obj.processing(false);
-        }
-        else
-        {
-            log_error(_("%s: Couldn't find onData"), __FUNCTION__);
-        }
-
-    }
+    if (msgs.empty()) return;
+    
+    log_debug(_("Got %d messages: "), msgs.size());
+
+#ifdef GNASH_DEBUG
+    for (size_t i = 0, e = msgs.size(); i != e; ++i)
+    {
+        log_debug(_(" Message %d: %s "), i, msgs[i]);
+    }
+#endif
+
+    boost::intrusive_ptr<as_function> onDataHandler = 
getEventHandler("onData");
+    if ( onDataHandler )
+    {
+        for (XMLSocket_as::MessageList::iterator it=msgs.begin(),
+                                               itEnd=msgs.end();
+                   it != itEnd; ++it)
+        {
+                       std::string& s = *it;
+                       as_value datain( s );
+
+                       as_environment env;
+                       env.push(datain);
+                       fn_call call(this, &env, 1, env.stack_size() - 1);
+                       onDataHandler->call(call);
+        }
+    }
+
 }
 
 } // end of gnash namespace

=== modified file 'libcore/asobj/XMLSocket_as.h'
--- a/libcore/asobj/XMLSocket_as.h      2008-08-25 06:59:44 +0000
+++ b/libcore/asobj/XMLSocket_as.h      2008-08-25 13:48:50 +0000
@@ -18,71 +18,12 @@
 #ifndef GNASH_XMLSOCKET_H
 #define GNASH_XMLSOCKET_H
 
-#include "xml.h"
-#include "impl.h"
-#include "network.h"
-#include "dsodefs.h"
-
-#include <string>
-
 namespace gnash {
   
-class XMLSocket : public Network {
-public:
-    XMLSocket();
-    ~XMLSocket();
-    
-    bool connect(const std::string& host, short port);
-    bool send(std::string str);
-    void close();
-
-    typedef std::vector<std::string> MessageList;
-
-    bool anydata(MessageList& msgs);
-    bool anydata(int sockfd, MessageList& msgs);
-    
-    bool fdclosed() { return _closed; }
-    bool xmlmsg() { return _xmldata; }
-    
-    void messagesClear()      { _messages.clear(); }
-    void messageRemove(int x) { _messages.erase(_messages.begin() + x); }
-    int messagesCount()       { return _messages.size(); }
-    std::string operator [] (int x)  { return _messages[x]; }
-    
-    bool processingData();
-    void processing(bool x);
-    
-    // Event Handlers
-    void onClose(std::string);
-    void onConnect(std::string);
-    void onData(std::string);
-    void onXML(std::string);
-    
-    // These handle the array of XML nodes
-    //void push(as_object *obj) { _nodes.push_back(obj); }
-    //void clear() { _nodes.clear(); }
-    //int  count() { return _nodes.size(); }
-    
-    int checkSockets(void);
-    int checkSockets(int x);
-    
-private:
-    bool          _data;
-    bool          _xmldata;
-    bool          _closed;
-    bool          _processing;
-    std::vector<std::string> _messages;
-
-    std::string _remainder;
-
-};
-
 void xmlsocket_class_init(as_object& global);
 
 } // end of gnash namespace
 
-
-// __XMLSOCKETSOCKET_H__
 #endif
 
 // Local Variables:

=== modified file 'libcore/asobj/xmlnode.cpp'
--- a/libcore/asobj/xmlnode.cpp 2008-08-25 10:16:16 +0000
+++ b/libcore/asobj/xmlnode.cpp 2008-08-25 12:45:03 +0000
@@ -403,7 +403,7 @@
     XMLNode *xml_obj = new XMLNode;
     if ( fn.nargs > 0 )
     {
-        xml_obj->nodeTypeSet(XMLNode::NodeType(int(fn.arg(0).to_number())));
+        xml_obj->nodeTypeSet(XMLNode::NodeType(fn.arg(0).to_int()));
         if (fn.nargs > 1)
         {
             xml_obj->nodeValueSet(fn.arg(1).to_string());

=== modified file 'testsuite/actionscript.all/XMLSocket.as'
--- a/testsuite/actionscript.all/XMLSocket.as   2008-04-01 08:26:53 +0000
+++ b/testsuite/actionscript.all/XMLSocket.as   2008-08-25 13:22:17 +0000
@@ -20,10 +20,27 @@
 // compile this test case with Ming makeswf, and then
 // execute it like this gnash -1 -r 0 -v out.swf
 
+// The attempted connections here should always fail. See
+// misc-ming.all/XMLSocketTest.c and testsuite/XmlSocketServer.pl
+// for tests with a running server.
 
 rcsid="$Id: XMLSocket.as,v 1.10 2008/04/01 09:26:54 strk Exp $";
 #include "check.as"
 
+#if OUTPUT_VERSION < 6
+XMLSocket.prototype.hasOwnProperty = ASnative(101, 5);
+#endif
+
+check(XMLSocket.prototype.hasOwnProperty("connect"));
+check(XMLSocket.prototype.hasOwnProperty("send"));
+check(XMLSocket.prototype.hasOwnProperty("close"));
+check(XMLSocket.prototype.hasOwnProperty("onData"));
+
+check(!XMLSocket.prototype.hasOwnProperty("onXML"));
+check(!XMLSocket.prototype.hasOwnProperty("onConnect"));
+check(!XMLSocket.prototype.hasOwnProperty("onClose"));
+
+
 check_equals(typeof(XMLSocket), 'function');
 check_equals(typeof(XMLSocket.connect), 'undefined');
 check_equals(typeof(XMLSocket.close), 'undefined');
@@ -36,12 +53,7 @@
 check_equals(typeof(XMLSocket.prototype.send), 'function');
 check_equals(typeof(XMLSocket.prototype.Connected), 'undefined');
 check_equals(typeof(XMLSocket.prototype.connected), 'undefined');
-#if OUTPUT_VERSION >= 6
-check(XMLSocket.prototype.hasOwnProperty('connect'));
-check(XMLSocket.prototype.hasOwnProperty('close'));
-check(XMLSocket.prototype.hasOwnProperty('send'));
-check(XMLSocket.prototype.hasOwnProperty('onData'));
-#endif
+
 
 socketObj = new XMLSocket;
 
@@ -68,14 +80,6 @@
        }
 };
 
-#if 0 // the default onData calls onXML
-socketObj.onData = function(src) {
-       check_equals(this.secret, 4);
-       check_equals(typeof(src), 'string');
-       note("XMLSocket.onData("+src+") called with "+arguments.length+" args");
-    this.onXML(new XML(src));
-};
-#endif
 
 socketObj.onXML = function(x) {
        check_equals(this.secret, 4);
@@ -90,32 +94,23 @@
        note("XMLSocket.onClose() called with "+arguments.length);
 };
 
-host = 'localhost';
-port = 3660;
-ret = socketObj.connect(host, port);
-if (ret) {
-       note("XMLSocket.connect("+host+", "+port+") returned true");
-} else {
-       note("XMLSocket.connect("+host+", "+port+") returned false");
-}
-
-#if 0 // disabled reconnect to avoid closing the socket prematurely
-host = null;
-port = 3660;
-ret = socketObj.connect(host, port);
-if (ret) {
-       note("XMLSocket.connect("+host+", "+port+") returned true");
-} else {
-       note("XMLSocket.connect("+host+", "+port+") returned false");
-}
-
-host = 'localhost';
-port = 3661;
-ret = socketObj.connect(host, port);
-if (ret) {
-       note("XMLSocket.connect("+host+", "+port+") returned true");
-} else {
-       note("XMLSocket.connect("+host+", "+port+") returned false");
-}
-#endif
-totals();
+host = 'madeuphost';
+port = 1090929898;
+
+// Connect should fail
+check_equals(socketObj.connect(host, port), false);
+// And again
+check_equals(socketObj.connect(host, port), false);
+
+// Close returns undefined, and we'd like not to crash if we call
+// close when not connected.
+ret = socketObj.close();
+check_equals(ret, undefined);
+// And again.
+ret = socketObj.close();
+check_equals(ret, undefined);
+
+ret = socketObj.send("This won't work'");
+check_equals(ret, undefined);
+
+totals(29);

=== modified file 'testsuite/misc-ming.all/XMLSocketTest.c'
--- a/testsuite/misc-ming.all/XMLSocketTest.c   2008-08-21 16:27:35 +0000
+++ b/testsuite/misc-ming.all/XMLSocketTest.c   2008-08-25 15:16:42 +0000
@@ -16,14 +16,6 @@
  *
  */ 
 
-
-
-/* The test sends all the 
-
-
-
-*/
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <ming.h>
@@ -99,6 +91,8 @@
     /* Wait for connection */
     add_actions(mo, "stop();");
 
+    /* Check here that a successful XMLSocket.connect() returns
+       true */
     add_actions(mo,
         "wait = 0;"
         "count = -1;"
@@ -107,15 +101,10 @@
         "myXML.onConnect = handleConnect;"
         "myXML.onData = handleData;"
         "myXML.onClose = handleDisconnect;"
-        "myXML.connect(\"localhost\", 2229);"
+        "ret = myXML.connect(\"localhost\", 2229);"
+        "check_equals(ret, true);"
     );
 
-/*function closeConnection(){*/
-/*    trace("Closing connection to server.");*/
-/*    myXML.close();*/
-/*}*/
-
-
     /* The data we're going to send */
 
     add_actions(mo, 
@@ -234,6 +223,11 @@
     /* Last frame (8) */
     SWFMovie_nextFrame(mo);
 
+    /* Close the connection to make sure it has no evil effects */
+    add_actions(mo,
+        "myXML.close();"
+    );
+
     check_equals(mo, "receivedArray.length", "expectedArray.length");
     
     check_equals(mo, "receivedArray[0]", "expectedArray[0]");


reply via email to

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