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: for i in self.disconnect_handlers:
i() i()
self.disconnect_handlers.reverse() 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'): if self.__dict__.has_key('NonBlockingNonSASL'):
self.NonBlockingNonSASL.PlugOut() self.NonBlockingNonSASL.PlugOut()
if self.__dict__.has_key('SASL'): if self.__dict__.has_key('SASL'):
@ -95,12 +88,11 @@ class NBCommonClient(CommonClient):
self.NBHTTPPROXYsocket.PlugOut() self.NBHTTPPROXYsocket.PlugOut()
if self.__dict__.has_key('NonBlockingTcp'): if self.__dict__.has_key('NonBlockingTcp'):
self.NonBlockingTcp.PlugOut() self.NonBlockingTcp.PlugOut()
if not self.connect(server=self._Server, proxy=self._Proxy):
return def reconnectAndReauth(self):
if not self.auth(self._User, self._Password, self._Resource): ''' Just disconnect. We do reconnecting in connection.py '''
return self.disconnect()
self.Dispatcher.restoreHandlers(handlerssave) return ''
return self.connected
def connect(self,server=None,proxy=None, ssl=None, on_stream_start = None): 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. ''' ''' 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 # we are not waiting for write
self._plug_idle() self._plug_idle()
self._on_send() self._on_send()
except Exception: except socket.error, e:
sys.exc_clear() sys.exc_clear()
if e[0] == socket.SSL_ERROR_WANT_WRITE:
return True
if self.state < 0: if self.state < 0:
self.disconnect() self.disconnect()
return return
@ -308,8 +310,9 @@ class NonBlockingTcp(PlugIn, IdleObject):
return True return True
def send(self, raw_data): def send(self, raw_data):
''' Writes raw outgoing data. Blocks until done. '''Append raw_data to the queue of messages to be send.
If supplied data is unicode string, encodes it to utf-8 before send. ''' If supplied data is unicode string, encode it to utf-8.
'''
if self.state <= 0: if self.state <= 0:
return return
r = raw_data r = raw_data