diff options
author | Nathan Fritz <nathan@andyet.net> | 2010-04-13 19:35:47 -0700 |
---|---|---|
committer | Nathan Fritz <nathan@andyet.net> | 2010-04-13 19:35:47 -0700 |
commit | fef511fd518d98a6934bd8048292d07380675d16 (patch) | |
tree | 01ac929d270df2dbc1a89f7bfc6cbd541ec06144 | |
parent | 85c3d97d2a2621c9a0022af3f3545848b8012519 (diff) | |
download | slixmpp-fef511fd518d98a6934bd8048292d07380675d16.tar.gz slixmpp-fef511fd518d98a6934bd8048292d07380675d16.tar.bz2 slixmpp-fef511fd518d98a6934bd8048292d07380675d16.tar.xz slixmpp-fef511fd518d98a6934bd8048292d07380675d16.zip |
bugfix for .disconnect() hanging
-rw-r--r-- | sleekxmpp/xmlstream/stanzabase.py | 2 | ||||
-rw-r--r-- | sleekxmpp/xmlstream/xmlstream.py | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 960e8a71..acb95786 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -210,6 +210,8 @@ class ElementBase(tostring.ToString): return self def __eq__(self, other): + if not isinstance(other, ElementBase): + return False values = self.getValues() for key in other: if key not in values or values[key] != other[key]: diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py index e208dba7..025884b7 100644 --- a/sleekxmpp/xmlstream/xmlstream.py +++ b/sleekxmpp/xmlstream/xmlstream.py @@ -53,7 +53,7 @@ class XMLStream(object): self.ssl_support = ssl_support self.escape_quotes = escape_quotes self.state = statemachine.StateMachine() - self.state.addStates({'connected':False, 'is client':False, 'ssl':False, 'tls':False, 'reconnect':True, 'processing':False}) #set initial states + self.state.addStates({'connected':False, 'is client':False, 'ssl':False, 'tls':False, 'reconnect':True, 'processing':False, 'disconnecting':False}) #set initial states self.setSocket(socket) self.address = (host, int(port)) @@ -168,7 +168,7 @@ class XMLStream(object): try: if self.state['is client']: self.sendRaw(self.stream_header) - while self.__readXML(): + while self.run and self.__readXML(): if self.state['is client']: self.sendRaw(self.stream_header) except KeyboardInterrupt: @@ -222,6 +222,7 @@ class XMLStream(object): if event == b'end': edepth += -1 if edepth == 0 and event == b'end': + self.disconnect(reconnect=self.state['reconnect']) return False elif edepth == 1: #self.xmlin.put(xmlobj) @@ -245,6 +246,7 @@ class XMLStream(object): #self.socket.send(bytes(data, "utf-8")) #except socket.error,(errno, strerror): except: + logging.warning("Failed to send %s" % data) self.state.set('connected', False) if self.state.reconnect: logging.error("Disconnected. Socket Error.") @@ -257,8 +259,15 @@ class XMLStream(object): def disconnect(self, reconnect=False): self.state.set('reconnect', reconnect) + if self.state['disconnecting']: + return + if not self.state['reconnect']: + logging.debug("Disconnecting...") + self.state.set('disconnecting', True) + self.run = False if self.state['connected']: self.sendRaw(self.stream_footer) + time.sleep(1) #send end of stream #wait for end of stream back try: |