[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/network.cpp libbase/net...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/network.cpp libbase/net... |
Date: |
Tue, 03 Apr 2007 15:24:12 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/04/03 15:24:11
Modified files:
. : ChangeLog
libbase : network.cpp network.h
server/asobj : xmlsocket.cpp xmlsocket.h
Log message:
* 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
members and methods. Enable some more debugging and added
more assertions.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.2763&r2=1.2764
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/network.cpp?cvsroot=gnash&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/network.h?cvsroot=gnash&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.cpp?cvsroot=gnash&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/xmlsocket.h?cvsroot=gnash&r1=1.6&r2=1.7
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.2763
retrieving revision 1.2764
diff -u -b -r1.2763 -r1.2764
--- ChangeLog 3 Apr 2007 14:07:21 -0000 1.2763
+++ ChangeLog 3 Apr 2007 15:24:11 -0000 1.2764
@@ -1,5 +1,13 @@
2007-04-03 Sandro Santilli <address@hidden>
+ * 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
+ members and methods. Enable some more debugging and added
+ more assertions.
+
+2007-04-03 Sandro Santilli <address@hidden>
+
* testsuite/actionscript.all/XMLSocket.as: some more
testing.
* server/sprite_instance.{cpp,h}: split the
Index: libbase/network.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/network.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- libbase/network.cpp 30 Mar 2007 14:55:11 -0000 1.22
+++ libbase/network.cpp 3 Apr 2007 15:24:11 -0000 1.23
@@ -63,7 +63,15 @@
#define INADDR_NONE 0xffffffff
#endif
-Network::Network() : _ipaddr(INADDR_ANY), _sockfd(0), _listenfd(0), _port(0),
_connected(false), _debug(false), _timeout(5)
+Network::Network()
+ :
+ _ipaddr(INADDR_ANY),
+ _sockfd(0),
+ _listenfd(0),
+ _port(0),
+ _connected(false),
+ _debug(false),
+ _timeout(5)
{
//log_msg("%s", __PRETTY_FUNCTION__);
#ifdef HAVE_WINSOCK_H
@@ -88,17 +96,6 @@
#endif
}
-Network &
-Network::operator = (Network &net)
-{
- _sockfd = net.getFileFd();
- _port = net.getPort();
- _host = net.getHost();
- _connected = net.connected();
- _timeout = net.getTimeout();
- return *this;
-}
-
// Description: Create a tcp/ip network server. This creates a server
// that listens for incoming socket connections. This
// support IP aliasing on the host, and will sequntially
@@ -347,6 +344,8 @@
char thishostname[MAXHOSTNAMELEN];
struct protoent *proto;
+ assert( ! connected() );
+
if (port < 1024) {
log_error("Can't connect to priviledged port #%hd!", port);
_connected = false;
@@ -434,12 +433,14 @@
log_msg("\tport %d at IP %s for fd #%d", port,
::inet_ntoa(sock_in.sin_addr), _sockfd);
_connected = true;
+ assert(_sockfd > 0);
return true;
}
if (ret == -1) {
log_msg("The connect() socket for fd #%d never was available
for writing!",
_sockfd);
_sockfd = -1;
+ assert(!_connected);
return false;
}
}
@@ -455,6 +456,7 @@
#endif
_connected = true;
+ assert(_sockfd > 0);
return true;
}
Index: libbase/network.h
===================================================================
RCS file: /sources/gnash/gnash/libbase/network.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- libbase/network.h 17 Dec 2006 20:24:57 -0000 1.12
+++ libbase/network.h 3 Apr 2007 15:24:11 -0000 1.13
@@ -101,20 +101,27 @@
void toggleDebug(bool val);
bool send(const char *str);
- //#ifdef ENABLE_TESTING
+
// Accessors for testing
- bool connected() { return _connected; };
- int getFileFd() { return _sockfd; };
- int getListenFd() { return _listenfd; };
- short getPort() { return _port; };
- std::string getURL() { return _url; }
- std::string getProtocol() { return _protocol; }
- std::string getHost() { return _host; }
- std::string getPortStr() { return _portstr; }
- std::string getPath() { return _path; }
- int getTimeout() { return _timeout; }
- //#endif
- Network &operator = (Network &net);
+ bool connected()
+ {
+ assert ( ( _connected && _sockfd > 0 ) || ( ! _connected && _sockfd <=
0 ) );
+ return _connected;
+ };
+
+ int getFileFd() const { return _sockfd; };
+ int getListenFd() const { return _listenfd; };
+ short getPort() const { return _port; };
+ const std::string& getURL() const { return _url; }
+ const std::string& getProtocol() const { return _protocol; }
+ const std::string& getHost() const { return _host; }
+ const std::string& getPortStr() const { return _portstr; }
+ const std::string& getPath() const { return _path; }
+ int getTimeout() const { return _timeout; }
+
+ // Network is not copiable !
+ //Network &operator = (Network &net) {}
+
protected:
in_addr_t _ipaddr;
int _sockfd;
Index: server/asobj/xmlsocket.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- server/asobj/xmlsocket.cpp 30 Mar 2007 14:51:38 -0000 1.15
+++ server/asobj/xmlsocket.cpp 3 Apr 2007 15:24:11 -0000 1.16
@@ -97,7 +97,6 @@
_data = false;
_xmldata = false;
_closed = false;
- _connect = false;
_processing = false;
_port = 0;
_sockfd = 0;
@@ -114,9 +113,8 @@
{
GNASH_REPORT_FUNCTION;
bool success = createClient(host, port);
- _connect = success;
- assert(!_sockfd || _connected);
+ assert( success || ! connected() );
return success;
}
@@ -132,19 +130,22 @@
// 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(char **msgs)
{
- GNASH_REPORT_FUNCTION;
+ //GNASH_REPORT_FUNCTION;
+ assert(connected());
+ assert(_sockfd > 0);
return anydata(_sockfd, msgs);
}
bool XMLSocket::processingData()
{
- GNASH_REPORT_FUNCTION;
+ //GNASH_REPORT_FUNCTION;
//printf("%s: processing flags is is %d\n", __FUNCTION__, _processing);
return _processing;
}
@@ -159,6 +160,8 @@
bool
XMLSocket::anydata(int fd, char **msgs)
{
+ GNASH_REPORT_FUNCTION;
+
fd_set fdset;
struct timeval tval;
int ret = 0;
@@ -170,9 +173,10 @@
static char *leftover = 0;
int adjusted_size;
- //log_msg("%s: \n", __FUNCTION__);
if (fd <= 0) {
+ log_msg("fd <= 0, returning false");
+ assert(!connected());
return false;
}
@@ -189,33 +193,36 @@
// If interupted by a system call, try again
if (ret == -1 && errno == EINTR) {
- log_msg("The socket for fd #%d was interupted by a system call!\n",
+ log_msg("The socket for fd #%d was interupted by a system call!",
fd);
continue;
}
if (ret == -1) {
- log_error("The socket for fd #%d never was available!\n", fd);
+ log_error("%s: The socket for fd #%d never was available!",
+ __FUNCTION__, fd);
return false;
}
if (ret == 0) {
- //log_msg("There is no data in the socket for fd #%d!\n", fd);
+ log_msg("%s: There is no data in the socket for fd #%d!",
+ __FUNCTION__, fd);
return false;
}
if (ret > 0) {
- //log_msg("There is data in the socket for fd #%d!\n", fd);
- //break;
+ log_msg("%s: There is data in the socket for fd #%d!",
+ __FUNCTION__, fd);
+ break;
}
memset(buf, 0, INBUF);
ret = ::read(_sockfd, buf, INBUF-2);
cr = strlen(buf);
- //log_msg("%s: read %d bytes, first msg terminates at %d\n",
__FUNCTION__, ret, cr);
+ log_msg("%s: read %d bytes, first msg terminates at %d\n",
__FUNCTION__, ret, cr);
//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) {
adjusted_size = memadjust(ret + 1);
packet = new char[adjusted_size];
- //printf("Packet size is %d at %p\n", ret + 1, packet);
+ printf("Packet size is %d at %p\n", ret + 1, packet);
memset(packet, 0, adjusted_size);
strcpy(packet, ptr);
eom = strrchr(packet, '\n'); // drop the CR off the end if there
is one
@@ -225,7 +232,7 @@
//data.push_back(packet);
msgs[index] = packet;
msgs[index+1] = 0;
- //printf("%d: Pushing Packet of size %d at %p\n", __LINE__,
strlen(packet), packet);
+ printf("%d: Pushing Packet of size %d at %p\n", __LINE__,
strlen(packet), packet);
processing(false);
return true;
}
@@ -296,14 +303,13 @@
{
//GNASH_REPORT_FUNCTION;
- if ( ! _connect )
+ if ( ! connected() )
{
assert(!_sockfd);
log_warning("socket not initialized at XMLSocket.send() call time");
return false;
}
- str += '\0';
int ret = write(_sockfd, str.c_str(), str.size());
log_msg("%s: sent %d bytes, data was %s\n", __FUNCTION__, ret,
str.c_str());
@@ -340,29 +346,6 @@
GNASH_REPORT_FUNCTION;
}
-void
-XMLSocket::push(as_object *obj)
-{
- GNASH_REPORT_FUNCTION;
- _nodes.push_back(obj);
-}
-
-void
-XMLSocket::clear()
-{
- GNASH_REPORT_FUNCTION;
- for (unsigned int i=0; i< _nodes.size(); i++) {
- delete _nodes[i];
- }
-}
-
-int
-XMLSocket::count()
-{
- GNASH_REPORT_FUNCTION;
- return _nodes.size();
-}
-
int
XMLSocket::checkSockets(void)
{
@@ -389,17 +372,20 @@
// If interupted by a system call, try again
if (ret == -1 && errno == EINTR) {
- log_msg("The socket for fd #%d was interupted by a system call in this
thread!\n",
- fd);
+ log_msg("%s: The socket for fd #%d was interupted by a system call in
this thread!",
+ __FUNCTION__, fd);
}
if (ret == -1) {
- log_error("The socket for fd #%d never was available!\n", fd);
+ log_error("%s: The socket for fd #%d never was available!",
+ __FUNCTION__, fd);
}
if (ret == 0) {
- printf("There is no data in the socket for fd #%d!\n", fd);
+ log_msg("%s: There is no data in the socket for fd #%d!",
+ __FUNCTION__, fd);
}
if (ret > 0) {
- //printf("There is data in the socket for fd #%d!\n", fd);
+ log_msg("%s: There is data in the socket for fd #%d!",
+ __FUNCTION__, fd);
}
return ret;
@@ -420,35 +406,44 @@
#endif
boost::intrusive_ptr<xmlsocket_as_object> ptr =
ensureType<xmlsocket_as_object>(fn.this_ptr);
- std::string host = fn.arg(0).to_std_string(&fn.env());
- std::string port_str = fn.arg(1).to_std_string(&fn.env());
- int port = atoi(port_str.c_str());
- bool success = ptr->obj.connect(host.c_str(), port);
-
- if ( success )
+ if (ptr->obj.connected())
{
- static bool first = true; // This event handler should only be
executed once.
- if (!first)
- {
- log_warning("XMLSocket.onConnect() not being called the second
time (dunno why: check %s:%d)", __FILE__, __LINE__);
+ log_warning("XMLSocket.connect() called while already connected,
ignored");
}
- else
- {
- first = false; // dont call onConnect twice (is this correct??)
+ as_value hostval = fn.arg(0);
+ std::string host = hostval.to_std_string(&fn.env());
+ int port = int(fn.arg(1).to_number(&fn.env()));
+
+ bool success = ptr->obj.connect(host.c_str(), port);
+
+ // Actually, if first-stage connection was successful, we
+ // should NOT invoke onConnect(true) here, but postpone
+ // that event call to a second-stage connection checking,
+ // 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.
+ //
if (fn.this_ptr->get_member("onConnect", &method))
{
- // log_msg("FIXME: Found onConnect!\n");
- val = call_method0(method, &fn.env(), fn.this_ptr.get());
+ log_msg("XMLSocket.connect(): calling onConnect");
+ as_environment env;
+ env.push(success);
+ val = call_method(method, &env, ptr.get(), 1, env.stack_size()-1);
}
- // TODO: don't allocate on heap!
+ if ( success )
+ {
+ log_warning("Setting up timer for calling XMLSocket.onData()");
+
Timer timer;
boost::intrusive_ptr<builtin_function> ondata_handler = new
builtin_function(&xmlsocket_event_ondata, NULL);
- timer.setInterval(*ondata_handler, 50,
boost::dynamic_pointer_cast<as_object>(ptr), &fn.env());
+ 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), &fn.env());
VM::get().getRoot().add_interval_timer(timer);
- }
+
+ log_warning("Timer set");
}
return as_value(success);
@@ -459,11 +454,9 @@
xmlsocket_send(const fn_call& fn)
{
GNASH_REPORT_FUNCTION;
- as_value method;
- as_value val;
boost::intrusive_ptr<xmlsocket_as_object> ptr =
ensureType<xmlsocket_as_object>(fn.this_ptr);
- const std::string object = fn.arg(0).to_string();
+ std::string object = fn.arg(0).to_std_string(&fn.env());
// log_msg("%s: host=%s, port=%g\n", __FUNCTION__, host, port);
return as_value(ptr->obj.send(object));
}
@@ -472,8 +465,6 @@
xmlsocket_close(const fn_call& fn)
{
GNASH_REPORT_FUNCTION;
- as_value method;
- as_value val;
boost::intrusive_ptr<xmlsocket_as_object> ptr =
ensureType<xmlsocket_as_object>(fn.this_ptr);
// Since the return code from close() doesn't get used by Shockwave,
@@ -488,23 +479,17 @@
//GNASH_REPORT_FUNCTION;
//log_msg("%s: nargs=%d\n", __FUNCTION__, nargs);
- as_object* xmlsock_obj = new xmlsocket_as_object;
+ boost::intrusive_ptr<as_object> xmlsock_obj = new xmlsocket_as_object;
#ifdef GNASH_XMLSOCKET_DEBUG
std::stringstream ss;
fn.dump_args(ss);
- log_msg("new XMLSocket(%s) called - created object at %p",
ss.str().c_str(), (void*)xmlsock_obj);
+ log_msg("new XMLSocket(%s) called - created object at %p",
ss.str().c_str(), (void*)xmlsock_obj.get());
#else
UNUSED(fn);
#endif
return as_value(xmlsock_obj);
-
- // Tune malloc for the best performance
- //mallopt(M_MMAP_MAX,0);
- //mallopt(M_TRIM_THRESHOLD,-1);
- //mallopt(M_MMAP_THRESHOLD,16);
-
}
@@ -513,6 +498,9 @@
{
GNASH_REPORT_FUNCTION;
+ //log_msg("doing nothing as this function is completely broken");
+ //return as_value();
+
as_value method;
as_value val;
as_value datain;
@@ -521,6 +509,12 @@
int i;
boost::intrusive_ptr<xmlsocket_as_object> ptr =
ensureType<xmlsocket_as_object>(fn.this_ptr);
+ if ( ! ptr->obj.connected() )
+ {
+ log_warning("XMLSocket not connected at xmlsocket_event_ondata
call");
+ return as_value();
+ }
+
if (ptr->obj.processingData()) {
log_msg("Still processing data!\n");
return as_value(false);
@@ -532,23 +526,30 @@
//dump_memory_stats(__FUNCTION__, __LINE__, "memory checkpoint");
#endif
- if (ptr->obj.anydata(messages)) {
- if (fn.this_ptr->get_member("onData", &method)) {
- //log_msg("Got %d messages from XMLsocket\n", msgs.size());
- // for (i=0; i<msgs.size(); i++) {
- for (i=0; messages[i] != 0; i++) {
+ 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 = new as_environment;
- env->push(datain);
- val = call_method(method, env, fn.this_ptr.get(), 1, 0);
- env->pop();
- delete env;
+ 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
@@ -558,11 +559,15 @@
datain.set_undefined();
}
ptr->obj.processing(false);
- } else {
- log_error("Couldn't find onData!\n");
}
+ 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++) {
+ for (i=0; messages[i] != 0; i++)
+ {
//log_msg("Deleting message #%d at %p\n", i, messages[i]);
delete messages[i];
}
@@ -570,8 +575,7 @@
//malloc_trim(0);
- //result->set(&data);
- return as_value(true);
+ return as_value();
}
static as_object*
Index: server/asobj/xmlsocket.h
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/xmlsocket.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- server/asobj/xmlsocket.h 30 Mar 2007 14:51:38 -0000 1.6
+++ server/asobj/xmlsocket.h 3 Apr 2007 15:24:11 -0000 1.7
@@ -43,7 +43,7 @@
bool anydata(char **msgs);
bool anydata(int sockfd, char **msgs);
- bool connected() { return _connect; };
+
bool fdclosed() { return _closed; }
bool xmlmsg() { return _xmldata; }
@@ -62,24 +62,20 @@
void onXML(std::string);
// These handle the array of XML nodes
- void push(as_object *obj);
- void clear();
- int count();
+ //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:
- std::string _host;
- short _port;
- int _sockfd;
bool _data;
bool _xmldata;
bool _closed;
- bool _connect;
bool _processing;
std::vector<std::string> _messages;
- std::vector<as_object *> _nodes;
+ //std::vector< boost::intrusive_ptr<as_object> > _nodes;
};
void xmlsocket_class_init(as_object& global);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/network.cpp libbase/net...,
Sandro Santilli <=