Commits

Anonymous committed 4a08ac0

backout better connection closing [396]

  • Participants
  • Parent commits edbcee4
  • Branches 0.5

Comments (0)

Files changed (12)

daemon/orbited/proxy.py

             self.remote_conn.send(item)
     
     def dataReceived(self, data):
-        print 'RECEIVED', data
-        if data[0] == '-':
-            return self.close()
-        else:
-            data = data[1:]
         getattr(self, 'state_' + self.state)(data)
     
     def state_initial(self, data):

daemon/orbited/static/BaseTCPConnection.js

         self.readyState = 1;
         getSession();
     }
-    self.close = function() {
-        if (self.readyState == 3) {
-            throw new Error("already closed")
-        }
-        doClose();
-    }
+        
     self.send = function(data) {
         sendQueue.push(data)
         if (!sending) {
     }
     
     var doSend = function() {
-        
         if (sendQueue.length == 0) {
             sending = false;
             return
         }
-        try {
-            sending = true;
-            numSent = sendQueue.length
-            xhr.open('POST', url.render(), true)
-            xhr.setRequestHeader('ack', ackId)
-            xhr.setRequestHeader('Tcp-Encoding', 'text')
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                sendQueue = sendQueue.slice(numSent)
-                                return doSend();
-                        }
-                        break;
-                }
+        sending = true;
+        numSent = sendQueue.length
+        xhr.open('POST', url.render(), true)
+        xhr.setRequestHeader('ack', ackId)
+        xhr.setRequestHeader('Tcp-Encoding', 'text')
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            sendQueue = sendQueue.slice(numSent)
+                            return doSend();
+                    }
+                    break;
             }
-            xhr.send(sendQueue.join(""))
         }
-        catch(e) {
-            // Something went wrong...
-            doClose()
-            // Note: when you refresh the page the above code will cause an error
-            //       on FF2+ for some reason. This is a good enough fix for now.
-        }
+        xhr.send(sendQueue.join(""))
     
     }
 
         self.onopen();
     }
     var doClose = function() {
+        if (self.readyState == 3) {
+            throw new Error("already closed")
+        }
         self.readyState = 3;
-        try {
-            if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-                xhr.onreadystatechange = function() {}
-                xhr.abort()
-            }
-            if (transport != null) {
-                transport.close()
-            }
-        }
-        catch(e) {
-            console.log(e)
-        }
         self.onclose();
     }
     var doRead = function(args) {

daemon/orbited/static/BinaryTCPSocket.js

     self.readyState = 0
 
     self.onread = function(packet) { }
-    self.close = function() {
-        if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-        self.readyState = 2
-        xhr.onreadystatechange = function() { }
-        xhr.abort()
-        xhr = null;        }
-    }
 
     self.connect = function(_url) {
         if (self.readyState == 1) {
         }
         xhr.send(null);
     }
-
+    self.disconnect = function() {
+        self.readyState = 2
+        xhr.onreadystatechange = function() { }
+        xhr.abort()
+        xhr = null;
+    }
     var reconnect = function() {
         offset = 0;
         setTimeout(open, self.retry)
     var self = this;
     id = ++HTMLFile.prototype.i;
     HTMLFile.prototype.instances[id] = self
-    var htmlfile = null
+    var htmlfile2 = null
     var url = null;
     self.onread = function(packet) { }
 
         self.readyState = 1
         doOpen()
     }
-    self.close = function() {
-        // TODO: I think this works -- couldn't test in IE. Will someone do that?
-        //       -mcarter 7-26-08
-        htmlfile = null;
-        CollectGarbage();
-    }
+
     var doOpenIfr = function() {
         
         var ifr = document.createElement('iframe')
     self.onread = function(packet) { }
     var source = null
     var url = null;
-
-    self.close = function() {
-        if (source != null) {
-            // TODO: can someone test this and get back to me? (No opera at the moment)
-            //     : -mcarter 7-26-08
-            source.removeEventSource(source.src)
-            source.src = ""
-            document.body.removeChild(source)
-            source = null;
-        }
-    }
-
-
     self.connect = function(_url) {
         if (self.readyState == 1) {
             throw new Error("Already Connected")
     open = function() {
         var source = document.createElement("event-source");
         source.setAttribute('src', url.render());
+//      TODO: uncomment this line to work in opera 8 - 9.27.
+//            there should be some way to make this work in both.
         if (opera.version() < 9.5) {
             document.body.appendChild(source);
         }
         source.addEventListener('orbited', receiveSSE, false);
     }
-
     var receiveSSE = function(event) {
         var data = eval(event.data);
         if (typeof(data) != 'undefined') {
         self.readyState = 1;
         getSession();
     }
-    self.close = function() {
-        if (self.readyState == 3) {
-            throw new Error("already closed")
-        }
-        doClose();
-    }
+        
     self.send = function(data) {
         sendQueue.push(data)
         if (!sending) {
     }
     
     var doSend = function() {
-        
         if (sendQueue.length == 0) {
             sending = false;
             return
         }
-        try {
-            sending = true;
-            numSent = sendQueue.length
-            xhr.open('POST', url.render(), true)
-            xhr.setRequestHeader('ack', ackId)
-            xhr.setRequestHeader('Tcp-Encoding', 'text')
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                sendQueue = sendQueue.slice(numSent)
-                                return doSend();
-                        }
-                        break;
-                }
+        sending = true;
+        numSent = sendQueue.length
+        xhr.open('POST', url.render(), true)
+        xhr.setRequestHeader('ack', ackId)
+        xhr.setRequestHeader('Tcp-Encoding', 'text')
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            sendQueue = sendQueue.slice(numSent)
+                            return doSend();
+                    }
+                    break;
             }
-            xhr.send(sendQueue.join(""))
         }
-        catch(e) {
-            // Something went wrong...
-            doClose()
-            // Note: when you refresh the page the above code will cause an error
-            //       on FF2+ for some reason. This is a good enough fix for now.
-        }
+        xhr.send(sendQueue.join(""))
     
     }
 
         self.onopen();
     }
     var doClose = function() {
+        if (self.readyState == 3) {
+            throw new Error("already closed")
+        }
         self.readyState = 3;
-        try {
-            if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-                xhr.onreadystatechange = function() {}
-                xhr.abort()
-            }
-            if (transport != null) {
-                transport.close()
-            }
-        }
-        catch(e) {
-            console.log(e)
-        }
         self.onclose();
     }
     var doRead = function(args) {

daemon/orbited/static/TCPSocket.js

     self.readyState = 0
 
     self.onread = function(packet) { }
-    self.close = function() {
-        if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-        self.readyState = 2
-        xhr.onreadystatechange = function() { }
-        xhr.abort()
-        xhr = null;        }
-    }
 
     self.connect = function(_url) {
         if (self.readyState == 1) {
         }
         xhr.send(null);
     }
-
+    self.disconnect = function() {
+        self.readyState = 2
+        xhr.onreadystatechange = function() { }
+        xhr.abort()
+        xhr = null;
+    }
     var reconnect = function() {
         offset = 0;
         setTimeout(open, self.retry)
     var self = this;
     id = ++HTMLFile.prototype.i;
     HTMLFile.prototype.instances[id] = self
-    var htmlfile = null
+    var htmlfile2 = null
     var url = null;
     self.onread = function(packet) { }
 
         self.readyState = 1
         doOpen()
     }
-    self.close = function() {
-        // TODO: I think this works -- couldn't test in IE. Will someone do that?
-        //       -mcarter 7-26-08
-        htmlfile = null;
-        CollectGarbage();
-    }
+
     var doOpenIfr = function() {
         
         var ifr = document.createElement('iframe')
     self.onread = function(packet) { }
     var source = null
     var url = null;
-
-    self.close = function() {
-        if (source != null) {
-            // TODO: can someone test this and get back to me? (No opera at the moment)
-            //     : -mcarter 7-26-08
-            source.removeEventSource(source.src)
-            source.src = ""
-            document.body.removeChild(source)
-            source = null;
-        }
-    }
-
-
     self.connect = function(_url) {
         if (self.readyState == 1) {
             throw new Error("Already Connected")
     open = function() {
         var source = document.createElement("event-source");
         source.setAttribute('src', url.render());
+//      TODO: uncomment this line to work in opera 8 - 9.27.
+//            there should be some way to make this work in both.
         if (opera.version() < 9.5) {
             document.body.appendChild(source);
         }
         source.addEventListener('orbited', receiveSSE, false);
     }
-
     var receiveSSE = function(event) {
         var data = eval(event.data);
         if (typeof(data) != 'undefined') {
         self.readyState = 1;
         getSession();
     }
-    self.close = function() {
-        if (self.readyState == 3) {
-            throw new Error("already closed")
-        }
-        doClose();
-    }
+        
     self.send = function(data) {
         sendQueue.push(data)
         if (!sending) {
     }
     
     var doSend = function() {
-        
         if (sendQueue.length == 0) {
             sending = false;
             return
         }
-        try {
-            sending = true;
-            numSent = sendQueue.length
-            xhr.open('POST', url.render(), true)
-            xhr.setRequestHeader('ack', ackId)
-            xhr.setRequestHeader('Tcp-Encoding', 'text')
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                sendQueue = sendQueue.slice(numSent)
-                                return doSend();
-                        }
-                        break;
-                }
+        sending = true;
+        numSent = sendQueue.length
+        xhr.open('POST', url.render(), true)
+        xhr.setRequestHeader('ack', ackId)
+        xhr.setRequestHeader('Tcp-Encoding', 'text')
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            sendQueue = sendQueue.slice(numSent)
+                            return doSend();
+                    }
+                    break;
             }
-            xhr.send(sendQueue.join(""))
         }
-        catch(e) {
-            // Something went wrong...
-            doClose()
-            // Note: when you refresh the page the above code will cause an error
-            //       on FF2+ for some reason. This is a good enough fix for now.
-        }
+        xhr.send(sendQueue.join(""))
     
     }
 
         self.onopen();
     }
     var doClose = function() {
+        if (self.readyState == 3) {
+            throw new Error("already closed")
+        }
         self.readyState = 3;
-        try {
-            if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-                xhr.onreadystatechange = function() {}
-                xhr.abort()
-            }
-            if (transport != null) {
-                transport.close()
-            }
-        }
-        catch(e) {
-            console.log(e)
-        }
         self.onclose();
     }
     var doRead = function(args) {
     var conn = new BaseTCPConnection()
 
     self.send = function(data) {
-        // First character is throwaway
-        conn.send("_" + data);
-    }
-    self.close = function(data) {
-        self.send("-")
-        self.onclose("")
+        conn.send(data);
     }
     conn.onread = function(data) {
         self.onread(data);
     }
     conn.onopen = function() {
         self.readyState = conn.readyState
-        self.send(domain + ":" + port)
+        conn.send(domain + ":" + port)
         self.onopen()
     }
     var connUrl = new URL(location.href)

daemon/orbited/static/TCPSocketImplementation.js

     var conn = new BaseTCPConnection()
 
     self.send = function(data) {
-        // First character is throwaway
-        conn.send("_" + data);
-    }
-    self.close = function(data) {
-        self.send("-")
-        self.onclose("")
+        conn.send(data);
     }
     conn.onread = function(data) {
         self.onread(data);
     }
     conn.onopen = function() {
         self.readyState = conn.readyState
-        self.send(domain + ":" + port)
+        conn.send(domain + ":" + port)
         self.onopen()
     }
     var connUrl = new URL(location.href)

daemon/orbited/static/WebSocket.js

     self.readyState = 0
 
     self.onread = function(packet) { }
-    self.close = function() {
-        if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-        self.readyState = 2
-        xhr.onreadystatechange = function() { }
-        xhr.abort()
-        xhr = null;        }
-    }
 
     self.connect = function(_url) {
         if (self.readyState == 1) {
         }
         xhr.send(null);
     }
-
+    self.disconnect = function() {
+        self.readyState = 2
+        xhr.onreadystatechange = function() { }
+        xhr.abort()
+        xhr = null;
+    }
     var reconnect = function() {
         offset = 0;
         setTimeout(open, self.retry)
     var self = this;
     id = ++HTMLFile.prototype.i;
     HTMLFile.prototype.instances[id] = self
-    var htmlfile = null
+    var htmlfile2 = null
     var url = null;
     self.onread = function(packet) { }
 
         self.readyState = 1
         doOpen()
     }
-    self.close = function() {
-        // TODO: I think this works -- couldn't test in IE. Will someone do that?
-        //       -mcarter 7-26-08
-        htmlfile = null;
-        CollectGarbage();
-    }
+
     var doOpenIfr = function() {
         
         var ifr = document.createElement('iframe')
     self.onread = function(packet) { }
     var source = null
     var url = null;
-
-    self.close = function() {
-        if (source != null) {
-            // TODO: can someone test this and get back to me? (No opera at the moment)
-            //     : -mcarter 7-26-08
-            source.removeEventSource(source.src)
-            source.src = ""
-            document.body.removeChild(source)
-            source = null;
-        }
-    }
-
-
     self.connect = function(_url) {
         if (self.readyState == 1) {
             throw new Error("Already Connected")
     open = function() {
         var source = document.createElement("event-source");
         source.setAttribute('src', url.render());
+//      TODO: uncomment this line to work in opera 8 - 9.27.
+//            there should be some way to make this work in both.
         if (opera.version() < 9.5) {
             document.body.appendChild(source);
         }
         source.addEventListener('orbited', receiveSSE, false);
     }
-
     var receiveSSE = function(event) {
         var data = eval(event.data);
         if (typeof(data) != 'undefined') {
         self.readyState = 1;
         getSession();
     }
-    self.close = function() {
-        if (self.readyState == 3) {
-            throw new Error("already closed")
-        }
-        doClose();
-    }
+        
     self.send = function(data) {
         sendQueue.push(data)
         if (!sending) {
     }
     
     var doSend = function() {
-        
         if (sendQueue.length == 0) {
             sending = false;
             return
         }
-        try {
-            sending = true;
-            numSent = sendQueue.length
-            xhr.open('POST', url.render(), true)
-            xhr.setRequestHeader('ack', ackId)
-            xhr.setRequestHeader('Tcp-Encoding', 'text')
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                sendQueue = sendQueue.slice(numSent)
-                                return doSend();
-                        }
-                        break;
-                }
+        sending = true;
+        numSent = sendQueue.length
+        xhr.open('POST', url.render(), true)
+        xhr.setRequestHeader('ack', ackId)
+        xhr.setRequestHeader('Tcp-Encoding', 'text')
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            sendQueue = sendQueue.slice(numSent)
+                            return doSend();
+                    }
+                    break;
             }
-            xhr.send(sendQueue.join(""))
         }
-        catch(e) {
-            // Something went wrong...
-            doClose()
-            // Note: when you refresh the page the above code will cause an error
-            //       on FF2+ for some reason. This is a good enough fix for now.
-        }
+        xhr.send(sendQueue.join(""))
     
     }
 
         self.onopen();
     }
     var doClose = function() {
+        if (self.readyState == 3) {
+            throw new Error("already closed")
+        }
         self.readyState = 3;
-        try {
-            if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-                xhr.onreadystatechange = function() {}
-                xhr.abort()
-            }
-            if (transport != null) {
-                transport.close()
-            }
-        }
-        catch(e) {
-            console.log(e)
-        }
         self.onclose();
     }
     var doRead = function(args) {

daemon/orbited/static/demos.local/chat/chat.js

 var CHANNEL = "#orbited"
-var IRC_SERVER = 'localhost'
+var IRC_SERVER = 'irc.freenode.net'
 var IRC_PORT = 6667
 
 var orig_domain = document.domain;

daemon/orbited/static/orbited.js

     self.readyState = 0
 
     self.onread = function(packet) { }
-    self.close = function() {
-        if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-        self.readyState = 2
-        xhr.onreadystatechange = function() { }
-        xhr.abort()
-        xhr = null;        }
-    }
 
     self.connect = function(_url) {
         if (self.readyState == 1) {
         }
         xhr.send(null);
     }
-
+    self.disconnect = function() {
+        self.readyState = 2
+        xhr.onreadystatechange = function() { }
+        xhr.abort()
+        xhr = null;
+    }
     var reconnect = function() {
         offset = 0;
         setTimeout(open, self.retry)
     var self = this;
     id = ++HTMLFile.prototype.i;
     HTMLFile.prototype.instances[id] = self
-    var htmlfile = null
+    var htmlfile2 = null
     var url = null;
     self.onread = function(packet) { }
 
         self.readyState = 1
         doOpen()
     }
-    self.close = function() {
-        // TODO: I think this works -- couldn't test in IE. Will someone do that?
-        //       -mcarter 7-26-08
-        htmlfile = null;
-        CollectGarbage();
-    }
+
     var doOpenIfr = function() {
         
         var ifr = document.createElement('iframe')
     self.onread = function(packet) { }
     var source = null
     var url = null;
-
-    self.close = function() {
-        if (source != null) {
-            // TODO: can someone test this and get back to me? (No opera at the moment)
-            //     : -mcarter 7-26-08
-            source.removeEventSource(source.src)
-            source.src = ""
-            document.body.removeChild(source)
-            source = null;
-        }
-    }
-
-
     self.connect = function(_url) {
         if (self.readyState == 1) {
             throw new Error("Already Connected")
     open = function() {
         var source = document.createElement("event-source");
         source.setAttribute('src', url.render());
+//      TODO: uncomment this line to work in opera 8 - 9.27.
+//            there should be some way to make this work in both.
         if (opera.version() < 9.5) {
             document.body.appendChild(source);
         }
         source.addEventListener('orbited', receiveSSE, false);
     }
-
     var receiveSSE = function(event) {
         var data = eval(event.data);
         if (typeof(data) != 'undefined') {
         self.readyState = 1;
         getSession();
     }
-    self.close = function() {
-        if (self.readyState == 3) {
-            throw new Error("already closed")
-        }
-        doClose();
-    }
+        
     self.send = function(data) {
         sendQueue.push(data)
         if (!sending) {
     }
     
     var doSend = function() {
-        
         if (sendQueue.length == 0) {
             sending = false;
             return
         }
-        try {
-            sending = true;
-            numSent = sendQueue.length
-            xhr.open('POST', url.render(), true)
-            xhr.setRequestHeader('ack', ackId)
-            xhr.setRequestHeader('Tcp-Encoding', 'text')
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                sendQueue = sendQueue.slice(numSent)
-                                return doSend();
-                        }
-                        break;
-                }
+        sending = true;
+        numSent = sendQueue.length
+        xhr.open('POST', url.render(), true)
+        xhr.setRequestHeader('ack', ackId)
+        xhr.setRequestHeader('Tcp-Encoding', 'text')
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            sendQueue = sendQueue.slice(numSent)
+                            return doSend();
+                    }
+                    break;
             }
-            xhr.send(sendQueue.join(""))
         }
-        catch(e) {
-            // Something went wrong...
-            doClose()
-            // Note: when you refresh the page the above code will cause an error
-            //       on FF2+ for some reason. This is a good enough fix for now.
-        }
+        xhr.send(sendQueue.join(""))
     
     }
 
         self.onopen();
     }
     var doClose = function() {
+        if (self.readyState == 3) {
+            throw new Error("already closed")
+        }
         self.readyState = 3;
-        try {
-            if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-                xhr.onreadystatechange = function() {}
-                xhr.abort()
-            }
-            if (transport != null) {
-                transport.close()
-            }
-        }
-        catch(e) {
-            console.log(e)
-        }
         self.onclose();
     }
     var doRead = function(args) {

daemon/orbited/static/protocols.local/irc/irc2.js

     self.connect = function(hostname, port) {
         log.debug("connect");
         conn = self._createTransport(hostname, port);
-        self.conn = conn
         conn.onopen = conn_opened
         conn.onclose = conn_closed
         conn.onread = conn_read
         log.debug("close");
         // XXX there is no TCPSocket.close method... so I'm removing all
         //     the listeners here (until this is fixed).
-        conn.close()
+        //conn.close()
         conn.onopen = null;
         conn.onclose = null;
         conn.onread = null;

daemon/orbited/static/transports/HTMLFile.js

     var self = this;
     id = ++HTMLFile.prototype.i;
     HTMLFile.prototype.instances[id] = self
-    var htmlfile = null
+    var htmlfile2 = null
     var url = null;
     self.onread = function(packet) { }
 
         self.readyState = 1
         doOpen()
     }
-    self.close = function() {
-        // TODO: I think this works -- couldn't test in IE. Will someone do that?
-        //       -mcarter 7-26-08
-        htmlfile = null;
-        CollectGarbage();
-    }
+
     var doOpenIfr = function() {
         
         var ifr = document.createElement('iframe')

daemon/orbited/static/transports/SSEAppXDom.js

     self.onread = function(packet) { }
     var source = null
     var url = null;
-
-    self.close = function() {
-        if (source != null) {
-            // TODO: can someone test this and get back to me? (No opera at the moment)
-            //     : -mcarter 7-26-08
-            source.removeEventSource(source.src)
-            source.src = ""
-            document.body.removeChild(source)
-            source = null;
-        }
-    }
-
-
     self.connect = function(_url) {
         if (self.readyState == 1) {
             throw new Error("Already Connected")
     open = function() {
         var source = document.createElement("event-source");
         source.setAttribute('src', url.render());
+//      TODO: uncomment this line to work in opera 8 - 9.27.
+//            there should be some way to make this work in both.
         if (opera.version() < 9.5) {
             document.body.appendChild(source);
         }
         source.addEventListener('orbited', receiveSSE, false);
     }
-
     var receiveSSE = function(event) {
         var data = eval(event.data);
         if (typeof(data) != 'undefined') {

daemon/orbited/static/transports/XHRStream.js

     self.readyState = 0
 
     self.onread = function(packet) { }
-    self.onclose = function() { }
-    self.close = function() {
-        if (xhr != null && (xhr.readyState > 1 || xhr.readyState < 4)) {
-            self.readyState = 2
-            xhr.onreadystatechange = function() { }
-            xhr.abort()
-            xhr = null;        
-        }
-    }
 
     self.connect = function(_url) {
         if (self.readyState == 1) {
         open()
     }
     open = function() {
-        try {
-            xhr.open('GET', url.render(), true)
-            if (typeof(ackId) == "number")
-                xhr.setRequestHeader('ack', ackId)
-            xhr.onreadystatechange = function() {
-                switch(xhr.readyState) {
-                    case 3:
-                        process();
-                        break;
-                    case 4:
-                        switch(xhr.status) {
-                            case 200:
-                                process();
-                                reconnect();
-                                break;
-                            default:
-                                self.disconnect();
-                        }
-                }
+
+        xhr.open('GET', url.render(), true)
+        if (typeof(ackId) == "number")
+            xhr.setRequestHeader('ack', ackId)
+        xhr.onreadystatechange = function() {
+            switch(xhr.readyState) {
+                case 3:
+                    process();
+                    break;
+                case 4:
+                    switch(xhr.status) {
+                        case 200:
+                            process();
+                            reconnect();
+                            break;
+                        default:
+                            self.disconnect();
+                    }
             }
-            xhr.send(null);
         }
-        catch(e) {
-            self.close()
-        }
+        xhr.send(null);
     }
-
+    self.disconnect = function() {
+        self.readyState = 2
+        xhr.onreadystatechange = function() { }
+        xhr.abort()
+        xhr = null;
+    }
     var reconnect = function() {
         offset = 0;
         setTimeout(open, self.retry)