mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-12-25 11:11:20 +00:00
bugfix for .disconnect() hanging
This commit is contained in:
parent
85c3d97d2a
commit
fef511fd51
2 changed files with 13 additions and 2 deletions
|
@ -210,6 +210,8 @@ class ElementBase(tostring.ToString):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, ElementBase):
|
||||||
|
return False
|
||||||
values = self.getValues()
|
values = self.getValues()
|
||||||
for key in other:
|
for key in other:
|
||||||
if key not in values or values[key] != other[key]:
|
if key not in values or values[key] != other[key]:
|
||||||
|
|
|
@ -53,7 +53,7 @@ class XMLStream(object):
|
||||||
self.ssl_support = ssl_support
|
self.ssl_support = ssl_support
|
||||||
self.escape_quotes = escape_quotes
|
self.escape_quotes = escape_quotes
|
||||||
self.state = statemachine.StateMachine()
|
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.setSocket(socket)
|
||||||
self.address = (host, int(port))
|
self.address = (host, int(port))
|
||||||
|
@ -168,7 +168,7 @@ class XMLStream(object):
|
||||||
try:
|
try:
|
||||||
if self.state['is client']:
|
if self.state['is client']:
|
||||||
self.sendRaw(self.stream_header)
|
self.sendRaw(self.stream_header)
|
||||||
while self.__readXML():
|
while self.run and self.__readXML():
|
||||||
if self.state['is client']:
|
if self.state['is client']:
|
||||||
self.sendRaw(self.stream_header)
|
self.sendRaw(self.stream_header)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@ -222,6 +222,7 @@ class XMLStream(object):
|
||||||
if event == b'end':
|
if event == b'end':
|
||||||
edepth += -1
|
edepth += -1
|
||||||
if edepth == 0 and event == b'end':
|
if edepth == 0 and event == b'end':
|
||||||
|
self.disconnect(reconnect=self.state['reconnect'])
|
||||||
return False
|
return False
|
||||||
elif edepth == 1:
|
elif edepth == 1:
|
||||||
#self.xmlin.put(xmlobj)
|
#self.xmlin.put(xmlobj)
|
||||||
|
@ -245,6 +246,7 @@ class XMLStream(object):
|
||||||
#self.socket.send(bytes(data, "utf-8"))
|
#self.socket.send(bytes(data, "utf-8"))
|
||||||
#except socket.error,(errno, strerror):
|
#except socket.error,(errno, strerror):
|
||||||
except:
|
except:
|
||||||
|
logging.warning("Failed to send %s" % data)
|
||||||
self.state.set('connected', False)
|
self.state.set('connected', False)
|
||||||
if self.state.reconnect:
|
if self.state.reconnect:
|
||||||
logging.error("Disconnected. Socket Error.")
|
logging.error("Disconnected. Socket Error.")
|
||||||
|
@ -257,8 +259,15 @@ class XMLStream(object):
|
||||||
|
|
||||||
def disconnect(self, reconnect=False):
|
def disconnect(self, reconnect=False):
|
||||||
self.state.set('reconnect', reconnect)
|
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']:
|
if self.state['connected']:
|
||||||
self.sendRaw(self.stream_footer)
|
self.sendRaw(self.stream_footer)
|
||||||
|
time.sleep(1)
|
||||||
#send end of stream
|
#send end of stream
|
||||||
#wait for end of stream back
|
#wait for end of stream back
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue