don't disconnect after server inabillity to

receive long data. Unregister all handlers in
disconnect
This commit is contained in:
Dimitur Kirov 2006-03-15 19:39:27 +00:00
parent f65a5be6e5
commit c8b27da04f
2 changed files with 20 additions and 25 deletions

View File

@ -78,13 +78,6 @@ class NBCommonClient(CommonClient):
for i in self.disconnect_handlers:
i()
self.disconnect_handlers.reverse()
if self.__dict__.has_key('NonBlockingTLS'):
self.NonBlockingTLS.PlugOut()
def reconnectAndReauth(self):
''' Example of reconnection method. In fact, it can be used to batch connection and auth as well. '''
handlerssave=self.Dispatcher.dumpHandlers()
self.Dispatcher.PlugOut()
if self.__dict__.has_key('NonBlockingNonSASL'):
self.NonBlockingNonSASL.PlugOut()
if self.__dict__.has_key('SASL'):
@ -95,12 +88,11 @@ class NBCommonClient(CommonClient):
self.NBHTTPPROXYsocket.PlugOut()
if self.__dict__.has_key('NonBlockingTcp'):
self.NonBlockingTcp.PlugOut()
if not self.connect(server=self._Server, proxy=self._Proxy):
return
if not self.auth(self._User, self._Password, self._Resource):
return
self.Dispatcher.restoreHandlers(handlerssave)
return self.connected
def reconnectAndReauth(self):
''' Just disconnect. We do reconnecting in connection.py '''
self.disconnect()
return ''
def connect(self,server=None,proxy=None, ssl=None, on_stream_start = None):
''' Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. '''

View File

@ -264,8 +264,10 @@ class NonBlockingTcp(PlugIn, IdleObject):
# we are not waiting for write
self._plug_idle()
self._on_send()
except Exception:
except socket.error, e:
sys.exc_clear()
if e[0] == socket.SSL_ERROR_WANT_WRITE:
return True
if self.state < 0:
self.disconnect()
return
@ -308,8 +310,9 @@ class NonBlockingTcp(PlugIn, IdleObject):
return True
def send(self, raw_data):
''' Writes raw outgoing data. Blocks until done.
If supplied data is unicode string, encodes it to utf-8 before send. '''
'''Append raw_data to the queue of messages to be send.
If supplied data is unicode string, encode it to utf-8.
'''
if self.state <= 0:
return
r = raw_data