[Pkg-javascript-commits] [ltx] 146/469: connection: deal with half-open sockets, wait for </stream:stream> before socket.end()

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit 5001cf1067974ff5e07478d5f510e60ce4cc7233
Author: Astro <astro at spaceboyz.net>
Date:   Sun Sep 12 00:39:07 2010 +0200

    connection: deal with half-open sockets, wait for </stream:stream> before socket.end()
---
 lib/xmpp/connection.js | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lib/xmpp/connection.js b/lib/xmpp/connection.js
index 816e163..8d98a29 100644
--- a/lib/xmpp/connection.js
+++ b/lib/xmpp/connection.js
@@ -90,6 +90,7 @@ Connection.prototype.startParser = function() {
         self.error(e.condition || 'internal-server-error', e.message);
     });
     this.parser.addListener('end', function() {
+        self.stopParser();
         self.end();
     });
 };
@@ -120,6 +121,8 @@ Connection.prototype.startStream = function() {
     el.t(' ');
     var s = el.toString();
     this.send(s.substr(0, s.indexOf(' </stream:stream>')));
+
+    this.streamOpened = true;
 };
 
 Connection.prototype.onData = function(data) {
@@ -176,7 +179,7 @@ Connection.prototype.addStreamNs = function(stanza) {
  */
 Connection.prototype.rmStreamNs = function(stanza) {
     for(var k in this.xmlns) {
-	var attr = k ? 'xmlns:' + k : 'xmlns';
+        var attr = k ? 'xmlns:' + k : 'xmlns';
         if (stanza.attrs[attr] == this.xmlns[k])
             delete stanza.attrs[attr];
     }
@@ -187,22 +190,24 @@ Connection.prototype.rmStreamNs = function(stanza) {
 /**
  * Connection has been ended by remote, we will not get any incoming
  * 'data' events. Alternatively, used for 'error' event.
- *
- * We don't deal with half-closed connections and end our half too.
  */
 Connection.prototype.onEnd = function() {
     this.stopParser();
-    this.end();
+    this.socket.end();
 };
 
 /**
  * XMPP-style end connection for user
  */
 Connection.prototype.end = function() {
-    if (this.socket.writable)
-        this.socket.write('</stream:stream>');
-    this.socket.end();
-    // stopParser will called on 'end'/'error' event
+    if (this.socket.writable) {
+        if (this.streamOpened) {
+            this.socket.write('</stream:stream>');
+            delete this.streamOpened;
+        } else {
+            this.socket.end();
+        }
+    }
 };
 
 /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list