mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 11:09:56 +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,10 +196,22 @@ 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:
|
||||
if not self.state.reconnect:
|
||||
return
|
||||
else:
|
||||
self.state.set('processing', False)
|
||||
traceback.print_exc()
|
||||
self.disconnect(reconnect=True)
|
||||
|
@ -247,8 +259,9 @@ 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)
|
||||
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