=== modified file 'libcore/asobj/XMLSocket_as.cpp' --- libcore/asobj/XMLSocket_as.cpp 2009-05-18 14:27:16 +0000 +++ libcore/asobj/XMLSocket_as.cpp 2009-05-26 19:38:25 +0000 @@ -38,6 +38,8 @@ #include #include #include +#include +#include #undef GNASH_XMLSOCKET_DEBUG @@ -97,6 +99,15 @@ _complete = true; } + bool lostConnection(){ + char buf[10]; + signal(SIGPIPE, SIG_IGN); + int r = recv(_socket.getFileFd(), buf, sizeof buf, MSG_PEEK); + log_debug(_("errno at lost connection, read: %d, err: %d"), r, errno); + signal(SIGPIPE, SIG_DFL); + return errno == EPIPE; + } + size_t writeMessage(const std::string& str) { // We have to write the null terminator as well. return write(_socket.getFileFd(), str.c_str(), str.size() + 1); @@ -293,6 +304,7 @@ // Wait until something has happened with the connection if (!_connection.complete()) return; + // If this XMLSocket hadn't finished a connection, check whether it // has now. if (!ready()) { @@ -312,6 +324,13 @@ _ready = true; } + if(_connection.lostConnection()){ + log_debug(_("call onClose")); + callMethod(NSV::PROP_ON_CLOSE); + _vm.getRoot().removeAdvanceCallback(this); + return; + } + // Now the connection is established we can receive data. checkForIncomingData(); } === modified file 'testsuite/XmlSocketServer.pl' --- testsuite/XmlSocketServer.pl 2008-08-20 16:15:55 +0000 +++ testsuite/XmlSocketServer.pl 2009-05-27 03:24:05 +0000 @@ -4,7 +4,7 @@ $SIG{PIPE}='IGNORE'; -$m=new IO::Socket::INET(Listen=>1,LocalPort=>2229); +$m=new IO::Socket::INET(Listen=>1,LocalPort=>8181); $O=new IO::Select($m); @@ -26,13 +26,14 @@ $T=syswrite($_, "\n", 16000); if ($T==undef) { $O->remove($_); + $_->close; } - } - else { - + } else { + # Sleep a bit before sending a reply to mimic web traffic # (well, sort of). Time::HiRes::sleep(0.5); + print "XmlSocketServer: sending \"$i\" \n"; $i =~ s/\*NEWLINE\*/\n/g; @@ -41,6 +42,12 @@ foreach $C($O->handles) { $T=syswrite($C, $i, 16000); } + + # Close client when receive the + if ($i =~ //ig ) { + $O->remove($_); + $_->close; + } } } }