mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-12-28 11:14:19 +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)
|
||||
|
||||
def disconnect(self, init=True, close=False, reconnect=False):
|
||||
print "** Called -- disconnected"
|
||||
# raise TypeError
|
||||
self.event("disconnected")
|
||||
XMLStream.disconnect(self, reconnect)
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ class basexmpp(object):
|
|||
return self.getId()
|
||||
|
||||
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))
|
||||
|
||||
def getId(self):
|
||||
|
|
|
@ -196,13 +196,25 @@ class XMLStream(object):
|
|||
self.state.set('processing', False)
|
||||
self.state.set('reconnect', False)
|
||||
self.disconnect()
|
||||
raise
|
||||
return
|
||||
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:
|
||||
self.state.set('processing', False)
|
||||
traceback.print_exc()
|
||||
self.disconnect(reconnect=True)
|
||||
if not self.state.reconnect:
|
||||
return
|
||||
else:
|
||||
self.state.set('processing', False)
|
||||
traceback.print_exc()
|
||||
self.disconnect(reconnect=True)
|
||||
if self.state['reconnect']:
|
||||
self.reconnect()
|
||||
self.state.set('processing', False)
|
||||
|
@ -247,9 +259,10 @@ class XMLStream(object):
|
|||
try:
|
||||
self.socket.send(data)
|
||||
except socket.error,(errno, strerror):
|
||||
logging.error("Disconnected. Socket Error #%s: %s" % (errno,strerror))
|
||||
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 True
|
||||
|
||||
|
@ -264,9 +277,12 @@ class XMLStream(object):
|
|||
self.filesocket.close()
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
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']:
|
||||
raise CloseStream
|
||||
#raise CloseStream
|
||||
pass
|
||||
|
||||
def reconnect(self):
|
||||
self.state.set('tls',False)
|
||||
|
|
Loading…
Reference in a new issue