made disconnect cleaner

This commit is contained in:
Nathan Fritz 2009-06-25 06:49:58 +00:00
parent 94f58ec3cb
commit ce8bf4a367
3 changed files with 26 additions and 12 deletions

View file

@ -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)

View file

@ -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):

View file

@ -196,10 +196,22 @@ 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:
if not self.state.reconnect:
return
else:
self.state.set('processing', False) self.state.set('processing', False)
traceback.print_exc() traceback.print_exc()
self.disconnect(reconnect=True) self.disconnect(reconnect=True)
@ -247,8 +259,9 @@ 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)
if self.state.reconnect:
logging.error("Disconnected. Socket Error #%s: %s" % (errno,strerror))
self.disconnect(reconnect=True) 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)