mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
made disconnect cleaner
This commit is contained in:
parent
94f58ec3cb
commit
ce8bf4a367
3 changed files with 26 additions and 12 deletions
|
@ -150,8 +150,6 @@ class ClientXMPP(basexmpp, XMLStream):
|
||||||
XMLStream.reconnect(self)
|
XMLStream.reconnect(self)
|
||||||
|
|
||||||
def disconnect(self, init=True, close=False, reconnect=False):
|
def disconnect(self, init=True, close=False, reconnect=False):
|
||||||
print "** Called -- disconnected"
|
|
||||||
# raise TypeError
|
|
||||||
self.event("disconnected")
|
self.event("disconnected")
|
||||||
XMLStream.disconnect(self, reconnect)
|
XMLStream.disconnect(self, reconnect)
|
||||||
|
|
||||||
|
|
|
@ -138,7 +138,7 @@ class basexmpp(object):
|
||||||
return self.getId()
|
return self.getId()
|
||||||
|
|
||||||
def add_handler(self, mask, pointer, disposable=False, threaded=False, filter=False):
|
def add_handler(self, mask, pointer, disposable=False, threaded=False, filter=False):
|
||||||
logging.warning("Deprecated add_handler used for %s: %s." % (mask, pointer))
|
#logging.warning("Deprecated add_handler used for %s: %s." % (mask, pointer))
|
||||||
self.registerHandler(XMLCallback('add_handler_%s' % self.getNewId(), MatchXMLMask(mask), pointer, threaded, disposable))
|
self.registerHandler(XMLCallback('add_handler_%s' % self.getNewId(), MatchXMLMask(mask), pointer, threaded, disposable))
|
||||||
|
|
||||||
def getId(self):
|
def getId(self):
|
||||||
|
|
|
@ -196,13 +196,25 @@ class XMLStream(object):
|
||||||
self.state.set('processing', False)
|
self.state.set('processing', False)
|
||||||
self.state.set('reconnect', False)
|
self.state.set('reconnect', False)
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
raise
|
return
|
||||||
except CloseStream:
|
except CloseStream:
|
||||||
break
|
return
|
||||||
|
except SystemExit:
|
||||||
|
return
|
||||||
|
except socket.EBADF:
|
||||||
|
if not self.state.reconnect:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
self.state.set('processing', False)
|
||||||
|
traceback.print_exc()
|
||||||
|
self.disconnect(reconnect=True)
|
||||||
except:
|
except:
|
||||||
self.state.set('processing', False)
|
if not self.state.reconnect:
|
||||||
traceback.print_exc()
|
return
|
||||||
self.disconnect(reconnect=True)
|
else:
|
||||||
|
self.state.set('processing', False)
|
||||||
|
traceback.print_exc()
|
||||||
|
self.disconnect(reconnect=True)
|
||||||
if self.state['reconnect']:
|
if self.state['reconnect']:
|
||||||
self.reconnect()
|
self.reconnect()
|
||||||
self.state.set('processing', False)
|
self.state.set('processing', False)
|
||||||
|
@ -247,9 +259,10 @@ class XMLStream(object):
|
||||||
try:
|
try:
|
||||||
self.socket.send(data)
|
self.socket.send(data)
|
||||||
except socket.error,(errno, strerror):
|
except socket.error,(errno, strerror):
|
||||||
logging.error("Disconnected. Socket Error #%s: %s" % (errno,strerror))
|
|
||||||
self.state.set('connected', False)
|
self.state.set('connected', False)
|
||||||
self.disconnect(reconnect=True)
|
if self.state.reconnect:
|
||||||
|
logging.error("Disconnected. Socket Error #%s: %s" % (errno,strerror))
|
||||||
|
self.disconnect(reconnect=True)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -264,9 +277,12 @@ class XMLStream(object):
|
||||||
self.filesocket.close()
|
self.filesocket.close()
|
||||||
self.socket.shutdown(socket.SHUT_RDWR)
|
self.socket.shutdown(socket.SHUT_RDWR)
|
||||||
except socket.error,(errno,strerror):
|
except socket.error,(errno,strerror):
|
||||||
logging.warning("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror))
|
#logging.warning("Error while disconnecting. Socket Error #%s: %s" % (errno, strerror))
|
||||||
|
#thread.exit_thread()
|
||||||
|
pass
|
||||||
if self.state['processing']:
|
if self.state['processing']:
|
||||||
raise CloseStream
|
#raise CloseStream
|
||||||
|
pass
|
||||||
|
|
||||||
def reconnect(self):
|
def reconnect(self):
|
||||||
self.state.set('tls',False)
|
self.state.set('tls',False)
|
||||||
|
|
Loading…
Reference in a new issue